1👍
As bryanph said use Values_list, and then to change the quotes from ASCII you need to escape them in the template. You can use the safe filter.
Line in View:
expenses = expense.values_list(‘month’, flat=True)
Template:
{{ expense|safe }}
0👍
Take a look at values_list: https://docs.djangoproject.com/es/1.9/ref/models/querysets/#values-list
This gives you lists of values rather than dictionaries.
- [Chartjs]-How to format x-axis time scale values in Chart.js v2
- [Chartjs]-Hide/disable tooltips chart.js
0👍
One way is to hook up underscore.js:
return render(request, 'home/index.html', json.dumps({"expense": expense}))
in the template:
data = JSON.parse({{ expense|safe }});
var labels = _.pluck(data, 'month');
var data = _.pluck(data, 'total_amount__sum');
Source:stackexchange.com