如何对每页中按日期分组的对象进行分页



尝试按对象的日期对对象列表进行分页。

例如:

page 1 -> objects date is smaller than today
page 2 -> objects date is equals to today
page 3 -> objects date is equals to tomorrow 

等等。每个页面可以有不同数量的元素。

来自django文档。

cities = [
{'name': 'Mumbai', 'population': '19,000,000', 'country': 'India'},
{'name': 'Calcutta', 'population': '15,000,000', 'country': 'India'},
{'name': 'New York', 'population': '20,000,000', 'country': 'USA'},
{'name': 'Chicago', 'population': '7,000,000', 'country': 'USA'},
{'name': 'Tokyo', 'population': '33,000,000', 'country': 'Japan'},
]
{% regroup cities by country as country_list %}
<ul>
{% for country in country_list %}
<li>{{ country.grouper }}
<ul>
{% for city in country.list %}
<li>{{ city.name }}: {{ city.population }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>

这正是你所需要的。在这里阅读更多django重组

最新更新