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

Thank you very much


--
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/61688c29-1d49-4d1a-9d04-45192d00c78d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Marc Aymerich at Oct 29, 2013 at 8:19 pm

    On Tue, Oct 29, 2013 at 8:45 PM, pywebdesign 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.
  • Xavier Ordoquy at Oct 29, 2013 at 8:46 pm
    Hi,

    You probably want to have a look at django rest framework.
    You use can will be easy with it, in particular if you use http://django-rest-framework.org/api-guide/viewsets.html#modelviewset

    Regards,
    Xavier.

    Le 29 oct. 2013 à 20:45, pywebdesign <pywebdesign@gmail.com> a écrit :
    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.

    Thank you very much



    --
    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/61688c29-1d49-4d1a-9d04-45192d00c78d%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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/27DD4867-A47A-4E9F-8417-1DF2D6F1E742%40linovia.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Pywebdesign at Oct 29, 2013 at 10:09 pm
    Ok, thank you! I was not doing it correctly at all.
    http://django-rest-framework.org is amazing.

    I am now using Marc's design and trying to event use CreateView and other
    generic view

    --
    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/0709023c-dc52-4fb2-bcb6-9474e99ee24c%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedOct 29, '13 at 7:45p
activeOct 29, '13 at 10:09p
posts4
users3
websitedjangoproject.com

People

Translate

site design / logo © 2022 Grokbase