CreateUpdateView view class
|Reported by:||Owned by:||nobody|
|Severity:||Normal||Keywords:||CBV class based view update create CreateUpdateView|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||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.
Change History (6)
comment:1 Changed 2 years ago by
|Patch needs improvement:||unset|