How do i paginate objects grouping by their date in each page?

Trying to paginate a list of objects by their date.

For example:

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

and so on. Each page can have different number of elements.

From django documentation.

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>

This is pretty much what you need. read more over here django regroup

Back to Top