Tuesday, October 29, 2013

Re: RestFul with Class Based Views best practice




On Tue, Oct 29, 2013 at 8:45 PM, pywebdesign <pywebdesign@gmail.com> wrote:
Hi,

I am trying to find/develop a best way to name and organize Views class to be consistent and flexible.

I am working on a project witch involve an model called Song. It's kind of a midi song in a database with attibutes about authors, name ... to make it simple.

Now I want web pages that permit to create a new song, edit a song, delete it or simply view it.
I also want a list page that list song by authors, by instrument (a typical search and return a list). the idea is to make the list editable via ajax. people change something on a list and it saves it to the browser when done without quitting the list. Very useful to modify many list at the same time.
There is also a page to create/upload 5 song at a time.

I was searching the best structure for my Class Based View. Right now I came up with this one:

class SongForm
def get_new_song
def post_new_song

def get_modify_song
def put_song

def get_delete_song
def delete_song

class SongListForm
def get_list_song(search infos)

class SongView
get_Song


ok that's about it. It look wrong, one big class and to very small one. I would like some pointer to some best practice to create this kind of CRUD as RESTFUL.


Hi, what i'd do if I want to be restful is create two views, one for listing and creating songs and another for reading, updating and deleting existing songs

class SongList
   # url /songs/
   def get: list songs
   def post: create new song

class Song
   # url /songs/<song_id>
   def get
   def put
   def patch
   def delete

I think with these two views you can cover all use-cases you've described :)

--
Marc

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BDCN_utdjJ39dY7kgE4-Nx7WXRpfVpe-Lo2V4CZsoUcJrn-SA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment