In [18]: index = 0
...: for short in Short.objects.raw("SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 15 OFFSET 0"):
...: print(short.id)
...: index=index+1
...: if index%5 == 0:
...: print()
...:
3896
464
1447
1448
1449
465
1915
466
467
1450
468
1916
1451
1917
469
In [23]: for short in Short.objects.raw("SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 5 OFFSET 0"):
...: print(short.id)
...:
3896
464
1447
1448
465
In [10]: for short in Short.objects.raw("SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 5 OFFSET 5"):
...: print(short.id)
...:
1449
1915
466
467
468
In [11]: for short in Short.objects.raw("SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 5 OFFSET 10"):
...: print(short.id)
...:
468
1916
1451
1917
469
As you can see,
SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 15 OFFSET 0
and
SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 5 OFFSET 0
SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 5 OFFSET 5
SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 5 OFFSET 10
It should be same result. Isn’t it?? but somehow specific row is skipped.
I am not sure why it happens?
I find that issue with using django core pagiantor like this
shorts = Short.objects.all().order_by('-created_at')
paginator = Paginator(shorts, page_per_item)
page_obj = paginator.get_page(page_number)
In [30]: for short in Short.objects.raw("SELECT * FROM shorts_short ORDER BY created_at DESC LIMIT 15 OFFSET 0"):
...: print(short.id, ":", short.created_at)
...:
3896 : 2024-04-13 09:00:00+00:00
464 : 2024-04-12 09:00:00+00:00
1447 : 2024-04-12 09:00:00+00:00
1448 : 2024-04-11 09:00:00+00:00
1449 : 2024-04-10 09:00:00+00:00
465 : 2024-04-10 09:00:00+00:00
1915 : 2024-04-09 09:00:00+00:00
466 : 2024-04-09 09:00:00+00:00
467 : 2024-04-06 09:00:00+00:00
1450 : 2024-04-05 09:00:00+00:00
468 : 2024-04-05 09:00:00+00:00
1916 : 2024-04-05 09:00:00+00:00
1451 : 2024-04-04 09:00:00+00:00
1917 : 2024-04-04 09:00:00+00:00
469 : 2024-04-03 09:00:00+00:00
The reason is same created_at.
Then how can I handle this for getting all list not duplicates.