Search code examples
djangopaginationdjango-viewsdjango-endless-pagination

How can i avoid repeating objects with endless pagination and order_by('?') queryset


I am using django-endless-pagination with its twitter-style pagination. Now i want to paginate over shuffled query set. I have tried to add

return Fact.objects.all().order_by('?')

But then objects can appear more than 1 time.
How can I change this behavior?


Solution

  • I think using pagination is misleading in this case. When the user clicks on page 2 it's not actually the second page, it's just another 20 items.
    A better option is having a single button (called Fetch for example) and fetch 20 items (or whatever the page size is) each time the user clicks on it.

    To avoid the same item showing up twice, you can keep a list of viewed ids in session and exclude them from the subsequent queries.