0

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?

pythad
  • 4,241
  • 2
  • 19
  • 41

2 Answers2

0

Another approach that you can take try is something that I used and I found on another StackOverflow post here.

import random
items = sorted(Fact.objects.all().order_by('nr'), key=lamda x: random.random())
return items
Community
  • 1
  • 1
Anthony Dito
  • 3,610
  • 3
  • 29
  • 56
0

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.

nima
  • 6,566
  • 4
  • 45
  • 57