#19375 closed Cleanup/optimization (needsinfo)
Class-based generic views + pagination hard to understand
Reported by: | 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 |
Description
The example template shown in the pagination section of the docs (https://docs.djangoproject.com/en/1.4/topics/pagination/) doesn't work with class-based generic views (such as ListView). However, the MultipleObjectMixins section (https://docs.djangoproject.com/en/1.4/ref/class-based-views/#multiple-object-mixins) 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 by , 12 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
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.
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:
and if you follow the link to the
Page
class docs you'll see the description ofhas_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?