Monday, October 14, 2013

Re: View for creating, listing, and deleting

Hi,

you are submitting two different problems, if I correctly understand your question. The first is about Create Read Update Delete objects, the second is about code reuse.

1. CRUD
From the user's point of view you should create a page with the list of objects, then provide a way to selectively delete some of them, and a way to create a new object.
For example you could have a button near each object that deletes it, and a general button that creates a new object.

The create button shall perform a GET on a page with a form, which in turn, when saved, shall perform a POST. This is done by a view (CreateView, if you want to use class based generic views). The delete button shall perform a POST, and this is usually done by hiding a prefilled form and submitting it through JS when pressing the delete button.

2. Code reuse
Since class-based generic views get a model as a parameter, I'd create a Factory, i.e. a class that returns a class. You can then loop over your models and call the Factory, generating urls on-th-fly.


Does this make sense for you? Let me know
Cheers,

Leo


Leonardo Giordani
Author of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile


2013/10/12 <plasmasheep@gmail.com>
I'm working on a project in which on a certain page I want to have a list of objects as well as the ability to delete and create them. I know that there are class-based generic views for these things, but I don't want three separate pages for these operations. What would be the best way to have them all on one page?

I'm guessing the right way to do it is to make a new class-based view for viewing, deleting, and listing objects of a certain kind and then to subclass for every object I need to list, create, or view, but I thought I'd make sure that's the best way to do it first.

--
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/44556c9b-8712-401c-b92b-62e124d1c93c%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/CAEhE%2BOkJL4ecO5WmU_ZL1znqYTVSD2EaEXFYgAGkXd3A25nEww%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate