0

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.

1 Answers1

0

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

Martins
  • 1,130
  • 10
  • 26
  • thanks for the response however i am trying to create infinite scroll and in each fetch i need to fetch the other day. i found that i need to use pagination to create infinite scroll but i guess django pagination doesnt support paginating by grouping in the view – ismail odabas Dec 14 '21 at 17:06