Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groupby filter ordering

Tags:

jinja2

Is it possible to make the groupby filter order in descending order? I have a list of dictionaries from a SQL query and I want to group by date in descending date order. From the manual:

{% for group in persons|groupby('gender') %}
    <li>{{ group.grouper }}<ul>
    {% for person in group.list %}
        <li>{{ person.first_name }} {{ person.last_name }}</li>
    {% endfor %}</ul></li>
{% endfor %}
like image 576
Clodoaldo Neto Avatar asked Jan 17 '23 03:01

Clodoaldo Neto


1 Answers

Try applying the reverse filter to the groupby('attribute') filter (e.g., {% for group in persons|groupby('gender')|reverse %})

like image 65
Garrett Avatar answered Mar 12 '23 15:03

Garrett