Opened 9 years ago

Closed 8 years ago

#4919 closed (fixed)

add ?page=last for generic object_list with pagination

Reported by: patrick@… Owned by: nobody
Component: Generic views Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


usecase: you want to link to the last page, but you don´t know how many pages there are. e.g, when you have comments paginated and you want to link to the last comment posted, you could use ?page=last

except (InvalidPage, ValueError):
    if page == 1 and allow_empty:
        object_list = []
+    elif page == 'last':
+        page = paginator._get_pages()
+        object_list = paginator.get_page(page - 1)
        raise Http404

sorry, but submitting a patch didn´t work the last time, so I just put the code in here.
the above code-snippet is for django.views.generic.list_detail.object_list from line 52.

Attachments (1)

lastpage.diff (3.8 KB) - added by nick@… 8 years ago.
Refactored patch plus generic views documentation

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 years ago by Simon G. <dev@…>

  • Has patch set
  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

This sounds like a good idea - but we'll need something in the docs about it. Can someone write up a patch that does Patrick's change, and adds a bit to the generic views docs?

Changed 8 years ago by nick@…

Refactored patch plus generic views documentation

comment:2 Changed 8 years ago by nick@…

  • Needs documentation unset
  • Patch needs improvement unset

comment:3 Changed 8 years ago by Simon G. <dev@…>

  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [6149]) Fixed #4919 -- Added 'last' marker on paginators. Thanks to patrick@… the idea, and nick@… for the patch and docs.

Note: See TracTickets for help on using tickets.
Back to Top