Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#22768 closed New feature (wontfix)

CreateUpdateView view class

Reported by: adi.andreias@… Owned by: nobody
Component: Generic views Version: dev
Severity: Normal Keywords: CBV class based view update create CreateUpdateView
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


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():

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.

Attachments (1) (1.5 KB) - added by adi.andreias@… 7 years ago.
a working code draft (alpha version)

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by adi.andreias@…

Attachment: added

a working code draft (alpha version)

comment:1 Changed 7 years ago by Maxime Turcotte

Cc: maxime.turcotte@… added

comment:2 Changed 7 years ago by Aymeric Augustin

I'm a bit skeptical. Django already gets criticized for providing too many generic views.

comment:3 Changed 7 years ago by anonymous

No need for this to be in core.

comment:4 Changed 7 years ago by Sasha Romijn

Resolution: wontfix
Status: newclosed

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.

comment:5 Changed 7 years ago by Maxime Turcotte

Cc: maxime.turcotte@… removed
Note: See TracTickets for help on using tickets.
Back to Top