[Django] #22768: CreateUpdateView view class

13 views
Skip to first unread message

Django

unread,
Jun 5, 2014, 7:45:46 AM6/5/14
to django-...@googlegroups.com
#22768: CreateUpdateView view class
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
adi.andreias@… | Status: new
Type: New | Version: master
feature | Keywords: CBV class based view update create
Component: Generic | CreateUpdateView
views | Has patch: 0
Severity: Normal | UI/UX: 0
Triage Stage: |
Unreviewed |
Easy pickings: 1 |
-------------------------+-------------------------------------------------
I think it makes sense to have a Class-based view for both updating and
creating model objects.

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.

Django

unread,
Jun 6, 2014, 9:39:51 AM6/6/14
to django-...@googlegroups.com
#22768: CreateUpdateView view class
-------------------------------------+-------------------------------------
Reporter: adi.andreias@… | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: master
Severity: Normal | Resolution:
Keywords: CBV class based | Triage Stage:
view update create | Unreviewed
CreateUpdateView | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by maxocub):

* cc: maxime.turcotte@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:1>

Django

unread,
Jun 6, 2014, 11:27:25 AM6/6/14
to django-...@googlegroups.com
#22768: CreateUpdateView view class
-------------------------------------+-------------------------------------
Reporter: adi.andreias@… | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: master
Severity: Normal | Resolution:
Keywords: CBV class based | Triage Stage:
view update create | Unreviewed
CreateUpdateView | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 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>

Django

unread,
Jun 12, 2014, 4:22:14 AM6/12/14
to django-...@googlegroups.com
#22768: CreateUpdateView view class
-------------------------------------+-------------------------------------
Reporter: adi.andreias@… | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: master
Severity: Normal | Resolution:
Keywords: CBV class based | Triage Stage:
view update create | Unreviewed
CreateUpdateView | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

No need for this to be in core.

--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:3>

Django

unread,
Jun 12, 2014, 2:58:15 PM6/12/14
to django-...@googlegroups.com
#22768: CreateUpdateView view class
-------------------------------------+-------------------------------------
Reporter: adi.andreias@… | Owner: nobody
Type: New feature | Status: closed

Component: Generic views | Version: master
Severity: Normal | Resolution: wontfix

Keywords: CBV class based | Triage Stage:
view update create | Unreviewed
CreateUpdateView | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by erikr):

* 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>

Django

unread,
Jun 12, 2014, 3:14:17 PM6/12/14
to django-...@googlegroups.com
#22768: CreateUpdateView view class
-------------------------------------+-------------------------------------
Reporter: adi.andreias@… | Owner: nobody
Type: New feature | Status: closed
Component: Generic views | Version: master
Severity: Normal | Resolution: wontfix
Keywords: CBV class based | Triage Stage:
view update create | Unreviewed
CreateUpdateView | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by maxocub):

* cc: maxime.turcotte@… (removed)


--
Ticket URL: <https://code.djangoproject.com/ticket/22768#comment:5>

Reply all
Reply to author
Forward
0 new messages