Jinja2 Group by Month/year

前端 未结 1 1021
自闭症患者
自闭症患者 2021-02-06 06:32

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\') %}
        <         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 06:40

    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') %}
            {{ month }} {{ year }}
    {% for event in list %} {{event.title}} {% endfor %} {% endfor %} {% endfor %}

    0 讨论(0)
提交回复
热议问题