I'm trying to group a list of date/times in Jinja by month/year. Here's the code I have right now:
{% for group in EventsList|groupby('date') %}
<b>{{group.grouper}}</b><br />
{% for event in group.list %}
<i>{{event.title}}</i>
{% endfor %}
{% endfor %}
But the problem is that it currently groups by a specific date. I'd like to group by Month/Year (i.e. January 2011, February 2011 etc..).
Would it be more efficient to do this in Python instead?
thanks!
You could first groupby('date.year') and then groupby('date.month').
{% for year, year_group in EventsList|groupby('date.year') %}
{% for month, list in year_group|groupby('date.month') %}
<b>{{ month }} {{ year }}</b><br />
{% for event in list %}
<i>{{event.title}}</i>
{% endfor %}
{% endfor %}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With