Clodoaldo Neto
Clodoaldo Neto

Reputation: 125414

Groupby filter ordering

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 %}

Upvotes: 4

Views: 3017

Answers (1)

Garrett
Garrett

Reputation: 49866

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

Upvotes: 9

Related Questions