【发布时间】:2018-02-09 20:47:11
【问题描述】:
我正在尝试按国家/地区对城市进行分组。
在我的模板中,以下工作 - 没有分组:
{% for item in object_list %}
{{ item.country}}
{{ item.city }}
{% endfor %}
但是,当我重新组合时:
{% regroup object_list by country as country_list %}
{% for item in country_list %}
{{ item.city }}
{% endfor %}
item.city 未呈现。
未分组的对象列表为:
<QuerySet [<Country: England>, <Country: France>, <Country: Germany>, <Country: Netherlands>]>
分组后:
Country: [GroupedResult(grouper=<Country: England>, list=[<City: Liverpool>, <City: London>, <City: Manchester>]), GroupedResult(grouper=<Country: Germany>, list=[<City: Munich>])....]
我做错了什么?
【问题讨论】:
标签: django-templates