Jinja2 Group by Month/year

前端 未结 1 1001
自闭症患者
自闭症患者 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') %}
            <b>{{ month }} {{ year }}</b><br />
            {% for event in list %}
                <i>{{event.title}}</i>
            {% endfor %}
        {% endfor %}
    {% endfor %}
    
    0 讨论(0)
提交回复
热议问题