Django重新组合不按预期循环

时间:2014-05-31 21:47:04

标签: django django-templates

我正在尝试按 event_id 对模板中的输出进行分组,但没有循环。如您所见,我在user_season_events中从我的SQL返回了数据。

我的模板中

{% regroup user_season_events by event_id as event_list %}

<ul>
{% for event in even_list %}
    <li> {{ event.grouper }}
    <ul>
        {% for item in event.list %}
          <li> points {{ item.points }}</li>
        {% endfor %}
    </ul>
    </li>
{% endfor %}
</ul>

我的查询结果(user_season_events):

user_season_events = UserEvent.objects. \
    raw("SELECT users_userevent.id, users_userevent.event_id, fights_fightchoice.points, users_uservote.event_id, "
            "fights_fightchoice.howitended_id, fights_fightchoice.fighter_id "
        "FROM users_userevent "
        "INNER JOIN events_event ON ( users_userevent.event_id = events_event.id )"
        "INNER JOIN users_user ON ( users_userevent.user_id = users_user.id )"
        "LEFT OUTER JOIN users_uservote ON ( events_event.id = users_uservote.event_id ) "
        "LEFT OUTER JOIN fights_fightchoice ON ( users_uservote.fightchoice_id = fights_fightchoice.id ) "
        "WHERE (events_event.season_id = " + season_id + " AND users_userevent.user_id = " + str(request.user.id) +
        " AND users_uservote.user_id = " + str(request.user.id) + " )"
        "ORDER BY events_event.event_on DESC   "
    )

context_dict = {'user_season_events': user_season_events}

enter image description here

1 个答案:

答案 0 :(得分:0)

拼写错误

{% for event in even_list %}

应该(错过事件中的t)

{% for event in event_list %}