2👍
✅
you can iterate on the query and build a list:
data = [{'name': item['browser'], 'y': item['browser_qty'] }
for item in parse_data_browser_result.all() ]
This is called a list comprehension.
Or you can still pass the queryset to the template and build the data like this:
data: [
{% for item in data.all() %}
{% if total > 0 %}
{ name: "{{ item['browser'] }}", y: {{ item['browser_qty'] }} },
{% endif %}
{% endfor %}
]
inside the <script>
.
Source:stackexchange.com