Hi,
I’ve been working on updates to gCBV docs. My goal is to make a much more
comprehensive coverage of how users may and should customize gCBVs.
I’ve worked on making a list of examples that covers the most useful
combinations in a clean and minimal fashion.
Here’s what I hope to accomplish:
- have a number of ready to use ‘canonical’ examples of customized gCBVs that
users can either use directly or tweak for their needs
- use the same examples to demonstrate the correct approach for creation of
arbitrary custom gCBVs, by following a sequence of steps:
* determine what functionality needs to be reused from existing gCBVs
* figure out the best way to extract the functionality, e.g. If a few
methods may be overridden, if instead get()/post() should be overridden and
directly implement some of the logic of downstream methods
* consider which classes should be inherited from, e.g. A mixin and a
specific view, two mixins and the base View, two specific views, etc.
* consider the sequence of inheritance
- document a few key gCBV methods from the point of view of customization, in
particular look at get_context_data(), how it can be used when customizing a
gCBV, how it can be used when mixing multiple gCBVs; the same for get() and
post() methods
I’ve also done two Pull requests that would make it easier to customize gCBVs.
Depending on whether these are accepted, some of the examples I’ve done can be
much simpler, and of course the documentation that I’m working on will be quite
different, because without these updates much of docs will have to be about
making workarounds to accomplish the same effect and why they’re needed.
Here’s the list of customized views I made (link to implementations below):
(note: below, Context* classes implement feature of one of the pull requests,
and so would not be needed if the change is accepted)
- combined DetailView and ListView.
- combined DetailView and ContextFormView.
- combined ListView and ContextFormView.
- NFormsView - class for processing arbitrary number of forms, accepting
input from only one of them that
user chose to submit. (inherits from FormView)
- combined create / update view, inherits from UpdateView.
- combined SingleObjectMixin, MultipleObjectMixin, ContextFormView.
- combined ListView and ContextCreateView.
- FormsetView, inherits from FormView, tweaked to process formset instead
of form.
- InlineFormsetView, inherits from FormView, tweaked to process inline
formset instead of form.
I’ve made a repository that includes the file with views defined and a wiki
page with an initial very rough draft of changes to docs (just the contents, no
django doc markup or links yet).
Here is the wiki page with links to both views file and the draft:
https://github.com/akulakov/gcbv-docs/wiki
The two pull requests:
https://github.com/django/django/pull/4512
https://github.com/django/django/pull/4526
I’m looking for feedback on general approach, on my implementations of the
custom views, on the two pull requests, and on the draft in the wiki.
I can package up a project with these views and all related modules / templates
if needed.
Thanks! - Andrei
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/D156E804.4CAB%25akulakov%40visual-a.com.
For more options, visit https://groups.google.com/d/optout.