Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#19375 closed Cleanup/optimization (needsinfo)

Class-based generic views + pagination hard to understand

Reported by: vtbassmatt@… Owned by: nobody
Component: Documentation Version: 1.4
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


The example template shown in the pagination section of the docs ( doesn't work with class-based generic views (such as ListView). However, the MultipleObjectMixins section ( suggests reading the pagination docs. I eventually figured out how to get it working thanks to a StackOverflow entry, but it would be great if the Django docs gave the correct information.

Concretely: If you set paginate_by in the constructor of ListView, then you don't use context_object.has_previous, context_object.has_next, etc. Instead, you use page_obj.has_previous, page_obj.has_next, etc. (page_obj is brought into the global namespace on the template rather than being represented by the context object.)

Change History (2)

comment:1 Changed 4 years ago by Aymeric Augustin

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: needsinfo
Status: newclosed

The generic CBV reference docs are always organized with a description, attributes, methods, and finally context variables.

The "Context" section of the CBV reference docs you're linking to say:

page_obj: An instance of django.core.paginator.Page. If the page is not paginated, this context variable will be None.

and if you follow the link to the Page class docs you'll see the description of has_previous, has_next and friends.

Yes, the reference docs for the generic CBVs can be overwhelming, because these views are built on a rich inheritance scheme and offer lots of options. But this part doesn't strike me as particularly badly organized or badly written.

What improvements would you suggest, without breaking the consistency with the rest of the generic CBV docs?

comment:2 Changed 4 years ago by vtbassmatt@…

Fair enough. On further consideration, what's actually needed is a good walkthrough for CBV. I don't understand the subject well enough to write it myself, but if/when I do, I'll be happy to contribute. Thanks for considering the change.

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