Group filter ordering

Is it possible to make the groupby filter groupby in descending order? I have a list of dictionaries from an SQL query and I want to group by date in descending order of date. 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 %} 
+4
source share
1 answer

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

+6
source

Source: https://habr.com/ru/post/1403000/


All Articles