[Answered ]-Pie chart highcharts from django query

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>.

Leave a comment