Opened 6 years ago

Closed 4 years ago

#14684 closed New feature (needsinfo)

RESTful Model View

Reported by: gdoermann Owned by: Łukasz Rekucki
Component: Generic views Version: 1.3-alpha
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
Easy pickings: no UI/UX: no

Description

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.

Thanks,

Greg

Attachments (1)

models.py (2.2 KB) - added by gdoermann 6 years ago.
models.py that could just be added to the views/generic folder.

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by gdoermann

Attachment: models.py added

models.py that could just be added to the views/generic folder.

comment:1 Changed 6 years ago by Alex Kamedov

Cc: kamedov@… added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 6 years ago by anonymous

Cc: paradise.qingfeng@… added

comment:3 Changed 6 years ago by Thomas Ashelford

milestone: 1.3
Triage Stage: UnreviewedDesign decision needed

Discussed this with Russell at the django sprint. The idea has merit, but needs way too much discussion to be included at this late stage in the 1.3 featureset. The present implementation of class-based views was intended as a drop-in replacement for the previous views system. This design takes things further.

comment:4 Changed 6 years ago by Thomas Ashelford

Keywords: sprintdec2010 added

comment:5 Changed 6 years ago by Łukasz Rekucki

Needs documentation: set
Needs tests: set
Owner: changed from nobody to Łukasz Rekucki
Patch needs improvement: set

I'm intrested in working on this for 1.4 :)

comment:6 Changed 6 years ago by Łukasz Rekucki

milestone: 1.4

comment:7 Changed 6 years ago by Łukasz Rekucki

Cc: lrekucki@… added

comment:8 Changed 6 years ago by Tom Christie

Cc: Tom Christie added

comment:9 Changed 6 years ago by James Addison

Severity: Normal
Type: New feature

comment:10 Changed 6 years ago by James Addison

milestone: 1.4

comment:11 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset
Triage Stage: Design decision neededSomeday/Maybe
UI/UX: unset

I don't agree entirely when the reporter says "the problem [...] is that [the views] are not RESTful". In my opinion, being RESTful isn't a goal in itself — it's a good thing only if it helps us build better websites faster.

I've seen excellent programmers, using a popular web framework designed around the REST theory, write incredible hacks to force their features in the REST mold, and more often than not it wasn't worth the complexity. I'm not thrilled by the hack to work around the lack of PUT and DELETE in current browsers (the action_name parameter) either, but I understand its existence.

That said, having shortcuts for typical RESTful views could be useful, if there's a clear gain compared to the current CBVs — maybe a one-liner in the URLconf to declare all the URLs?

As pointed out in comment 3, we'd need to discuss a detailed proposal on the django-developers mailing list before we can accept this feature.

comment:12 Changed 4 years ago by Aymeric Augustin

Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top