Thursday, September 8, 2011

Re: Binding two views to one url?

What you need to do is browse the class-based views docs for how to handle forms with them.

https://docs.djangoproject.com/en/dev/ref/class-based-views/#formview

Instead of switching from DetailView to FormView, you can just try to add some of the mixins that FormView uses. This way you can merge functionality from different classes:

https://docs.djangoproject.com/en/dev/ref/class-based-views/#django.views.generic.edit.FormMixin
https://docs.djangoproject.com/en/dev/ref/class-based-views/#django.views.generic.edit.ProcessFormView


The documentation is lacking, but try reading those three links and see what you come up with. Post again if you have any further questions and we'll be glad to help.


Cheers,
AT

On Thu, Sep 8, 2011 at 4:33 PM, Petey <efrinut@gmail.com> wrote:
Is it possible to bind two views to one url adress?

I have a generic view - detail_view and I prepared a form for comments.
Detail_views generates urls by "type", "pk", "slug" fields. Under each publication I'd like to add a form to add my comments model and I dont really know how I could do that.

URL - detail view:

url(r'^(?P<type>[\w\-_]+)/(?P<pk>\d+)/(?P<slug>[\w\-_]+)/$',
        DetailView.as_view(
                         model=Publisher,
                         template_name='templates/publications/single.html',
                            ),

                         name = "single_publication"
                         ),

VIEW for form:
def add_comment(request, type, pk, slug):
    form = CommentsForm()
    return render_to_response('templates/publications/single.html', {'form':form}, context_instance=RequestContext(request))

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Ke3ot3Kjd-8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment