Opened 6 years ago

Closed 4 years ago

#14684 closed New feature (needsinfo)

RESTful Model View

Reported by: gdoermann Owned by: lrekucki
Component: Generic views Version: 1.3-alpha
Severity: Normal Keywords: models, views, sprintdec2010
Cc: gdoermann@…, kamedov@…, paradise.qingfeng@…, lrekucki@…, tomchristie Triage Stage: Someday/Maybe
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no


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/ 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.



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

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by gdoermann that could just be added to the views/generic folder.

comment:1 Changed 6 years ago by alekam

  • 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 tttallis

  • milestone 1.3 deleted
  • Triage Stage changed from Unreviewed to Design 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 tttallis

  • Keywords sprintdec2010 added

comment:5 Changed 6 years ago by lrekucki

  • Needs documentation set
  • Needs tests set
  • Owner changed from nobody to lrekucki
  • Patch needs improvement set

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

comment:6 Changed 5 years ago by lrekucki

  • milestone set to 1.4

comment:7 Changed 5 years ago by lrekucki

  • Cc lrekucki@… added

comment:8 Changed 5 years ago by tomchristie

  • Cc tomchristie added

comment:9 Changed 5 years ago by jaddison

  • Severity set to Normal
  • Type set to New feature

comment:10 Changed 5 years ago by jaddison

  • milestone 1.4 deleted

comment:11 Changed 4 years ago by aaugustin

  • Easy pickings unset
  • Triage Stage changed from Design decision needed to Someday/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 aaugustin

  • Resolution set to needsinfo
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top