RESTful Model View
|Reported by:||gdoermann||Owned by:||Łukasz Rekucki|
|Severity:||Normal||Keywords:||models, views, sprintdec2010|
|Cc:||gdoermann@…, kamedov@…, paradise.qingfeng@…, lrekucki@…, Tom Christie||Triage Stage:||Someday/Maybe|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||yes|
I love the changes that now allow class views. I am probably a bit late in the discussion, but the problem with how they are currently designed is that in the views/generic/edit.py are not RESTful. You have to have a Create, Update and Delete view for each model. I spent some time writing a ModelView that uses the existing code, but allows for a single model view that takes care of all CRUD. The only drawback is that you must use an "action" hidden field whose name can be specified by the "action_name" variable if you want to delete and your browser does not support the DELETE HTTP verb. This is the current way of handling RESTful applications in non-RESTful browsers (or the best way I have found and read about). It does a safe get on the object so if the pk or slug are not passed in it assumes you are creating a new object (so... this could be changed to use the action key as well, but I just played off of what you were doing in the existing get_object for the ModelFormMixin).
Attached is the generic ModelFormView.
Change History (13)
comment:5 Changed 6 years ago by
|Owner:||changed from nobody to Łukasz Rekucki|
|Patch needs improvement:||set|
comment:11 Changed 5 years ago by
|Triage Stage:||Design decision needed → Someday/Maybe|