BaseUpdateView and BaseCreateView differ by just two lines, one in get()
and one in post():
https://github.com/django/django/blob/1.7b4/django/views/generic/edit.py#L218
https://github.com/django/django/blob/1.7b4/django/views/generic/edit.py#L195
A CreateUpdateView view would distinguish between create and update based
on a slug, pk or similar (configurable?) parameter in url.
There are situations where the view class contains a lot of code logic
(like a secondary formset, ajax requests handled along with regular
requests, etc.) and having separate classes for create and update would
result in duplicate code.
I also think this is a common pattern and deserves to be added to Django
core.
--
Ticket URL: <https://code.djangoproject.com/ticket/22768>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: maxime.turcotte@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:1>
Comment (by aaugustin):
I'm a bit skeptical. Django already gets criticized for providing too many
generic views.
--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:2>
Comment (by anonymous):
No need for this to be in core.
--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:3>
* status: new => closed
* resolution: => wontfix
Comment:
Assuming, as you say, that the only difference is those two lines, that
would also mean it is trivial to create this yourself: use a
`BaseUpdateView` based class, and override `get_object()` in your class to
return `None` whenever you want it to behave as a create view, instead of
an update view. That will not introduce any code duplication.
I'm closing wontfix, as I then consider this to be something that is
trivial to do, by design, outside of Django core.
--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:4>
* cc: maxime.turcotte@… (removed)
--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:5>