[Chartjs]-Django show Graphs with ChartJS

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.

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');

Leave a comment