Opened 8 years ago
Closed 8 years ago
#27997 closed Bug (duplicate)
Can't get last() item of a paginator 'page'
Reported by: | Thomas Capricelli | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It's easy to reproduce with manage.py shell:
>>> from django.core.paginator import Paginator >>> from xxx.models import * >>> paginator = Paginator(YourFavoriteModel.objects.all(), 30) >>> page = paginator.page(2) >>> page.object_list.first() in page.object_list True >>> page.object_list.last() in page.object_list False # Even if unrolled: >>> unrolled = [o for o in page.object_list] >>> page.object_list.first() in unrolled True >>> page.object_list.last() in unrolled False
Tested with python 2.7.13 and Django 1.8, 1.9 and 1.10.
I can reproduce it on several projects, with any Model that has an order defined in Meta. I can also reproduce for a Model that has none but adding an order_by("field") in the paginator=Paginator line.
What I do get with page.object_list.last() is indeed an item of the paginator queryset, but it doens't belong to the page, and is even far away. I have an example here where the item is in the middle of page 2 while i'm testing page 27 !
Change History (3)
comment:1 by , 8 years ago
comment:3 by , 8 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I believe this is a duplicate of #22550 -- QuerySet last() and reverse() confusing when used with ordered slices.