I am creating a variable queryset and then passing the values into a dictionary context variable. I am able to convert dates but I'm not sure how to convert specific fields to currency (example: $1,000 instead of 1000) or even just humanize specific fields with commas (1,000 instead of 1000) below is my code from my view, the two methods are a part of a class:
from datetime import date
def get_context_data(self):
context = super(MyView, self).get_context_data()
context['myview_items'] = self.get_mymethod_items_context()
return context
def get_mymethod_items_context(self):
context = {}
items = table.objects.values('date_begun', 'price', 'item_number')
context['items'] = items
context['headers'] = ['Date', 'Price', 'Item']
context['fields'] = ['date_begun_date', 'price', 'item_number']
return context
I only want to convert one field, which is what I was trying to do for the price field:
from django.contrib.humanize.templatetags.humanize import intcomma
intcomma('price')
How im creating tables, Template tag on my template:
{% simple_table_print 'tableid1' 'Price Information' myview_items.items myview_items.fields myview_items.headers %}