Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (19.9k points)

I'm using Django 2.1 I'm trying to iterate over a queryset using paginator. For some reason it looks like every iteration the pages content is different. for example on first iteration the first page contains some item, and in the next iteration, that item is now on the second page.

This is how I'm using it:

items_qs = Item.objects.all().filter(

        created_at__lte=on_date

    )

all_items_paginator = Paginator(items_qs, 1)

for page_number in all_items_paginator.page_range:

    page = all_items_paginator.page(page_number)

    items_ids_list = [item.id for item in page.object_list]

1 Answer

0 votes
by (25.1k points)

You should give your query an explicit ordering.

Item.objects.order_by("created_at").filter(...)

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 8, 2021 in Web Technology by Rekha (2.2k points)
0 votes
1 answer
asked Mar 8, 2021 in Web Technology by Rekha (2.2k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...