Re: Is it possible to display multiple forms in a single template file?
Thank you for the advise. I just started using Django and sometimes it takes time to get used to do certain things. Regards, Arif On Nov 20, 3:40 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2008-11-20 at 15:18 -0800, ayayalar wrote: > > I understand, I wish it was possible to bind multiple view functions > > to a single template through the urls... > > Why? It's the wrong level of coupling. Each URL patterns ends up > resolving to a single view function. However that view function can (and > should if there's any great level of processing involved) call other > functions to do whatever it wants. So just move your multiple function > calls down one layer. It retains the "view per URL" pattern and you can > still have one function for each form. You just need to merge the > results at the end, but since that's just a dictionary update, it's one > line of code. > > You are trying to make this way too hard for yourself by getting hung up > on one particular pattern of usage that you guessed might be possible > without any supporting evidence. Since that isn't possible in Django and > isn't ever likely to be possible, it's particularly counter-productive > not to move on, especially as the way to do this is trivial. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
On Thu, 2008-11-20 at 15:18 -0800, ayayalar wrote: > I understand, I wish it was possible to bind multiple view functions > to a single template through the urls... Why? It's the wrong level of coupling. Each URL patterns ends up resolving to a single view function. However that view function can (and should if there's any great level of processing involved) call other functions to do whatever it wants. So just move your multiple function calls down one layer. It retains the "view per URL" pattern and you can still have one function for each form. You just need to merge the results at the end, but since that's just a dictionary update, it's one line of code. You are trying to make this way too hard for yourself by getting hung up on one particular pattern of usage that you guessed might be possible without any supporting evidence. Since that isn't possible in Django and isn't ever likely to be possible, it's particularly counter-productive not to move on, especially as the way to do this is trivial. Regards, Malcolm --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
As you can see I am trying to display a form that points to related models/tables. Any suggestion where I can find a good documentation or an article to accomplish this in "Django" way? I feel like I am not taking the right path On Nov 20, 3:23 pm, ayayalar <[EMAIL PROTECTED]> wrote: > I am able to do this, but this is pure ugly. Not a very elegant way of > doing things. > > def product(request): > if not request.method == 'POST': > form1 = ProductForm() > form2 = ProductDetailForm() > return render_to_response('index.html', {'form1' : form1, > 'form2' : form2}) > else: > form1 = ProductForm(request.POST) > form2 = ProductDetailForm(request.POST) > if form1.is_valid(): > form1.save() > if form2.is_valid(): > form2.save() > return HttpResponseRedirect('/thanks.html') > > On Nov 20, 3:18 pm, ayayalar <[EMAIL PROTECTED]> wrote: > > > I understand, I wish it was possible to bind multiple view functions > > to a single template through the urls... > > > Would something like this possible? > > > URLS > > urlpatterns = patterns('', > > > (r'^product/$', views.add_product, views.add_product_details),) > > > On Nov 20, 3:07 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> > > wrote: > > > > On Thu, 2008-11-20 at 14:03 -0800, ayayalar wrote: > > > > [...] > > > > > URLS > > > > urlpatterns = patterns('', > > > > > (r'^product/$', views.add_product), > > > > (r'^product/$', views.add_product_details), > > > > This has no chance of doing what you expect. Only one view function will > > > be called for a single request. If you want to pass two form objects to > > > the template, you need to do it from the same view function. You can > > > still put the form creation pieces in separate functions, but your view > > > function will have to call both of them and combine the results into a > > > context to pass to a template. > > > > Regards, > > > Malcolm > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
I am able to do this, but this is pure ugly. Not a very elegant way of doing things. def product(request): if not request.method == 'POST': form1 = ProductForm() form2 = ProductDetailForm() return render_to_response('index.html', {'form1' : form1, 'form2' : form2}) else: form1 = ProductForm(request.POST) form2 = ProductDetailForm(request.POST) if form1.is_valid(): form1.save() if form2.is_valid(): form2.save() return HttpResponseRedirect('/thanks.html') On Nov 20, 3:18 pm, ayayalar <[EMAIL PROTECTED]> wrote: > I understand, I wish it was possible to bind multiple view functions > to a single template through the urls... > > Would something like this possible? > > URLS > urlpatterns = patterns('', > > (r'^product/$', views.add_product, views.add_product_details),) > > On Nov 20, 3:07 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > On Thu, 2008-11-20 at 14:03 -0800, ayayalar wrote: > > > [...] > > > > URLS > > > urlpatterns = patterns('', > > > > (r'^product/$', views.add_product), > > > (r'^product/$', views.add_product_details), > > > This has no chance of doing what you expect. Only one view function will > > be called for a single request. If you want to pass two form objects to > > the template, you need to do it from the same view function. You can > > still put the form creation pieces in separate functions, but your view > > function will have to call both of them and combine the results into a > > context to pass to a template. > > > Regards, > > Malcolm > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
On Nov 20, 4:50 pm, ayayalar <[EMAIL PROTECTED]> wrote: > And I do that. Here is my template: > No, you are not. Check the dictionary you are passing into your render_to_response() calls again. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
I understand, I wish it was possible to bind multiple view functions to a single template through the urls... Would something like this possible? URLS urlpatterns = patterns('', (r'^product/$', views.add_product, views.add_product_details),) On Nov 20, 3:07 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2008-11-20 at 14:03 -0800, ayayalar wrote: > > [...] > > > URLS > > urlpatterns = patterns('', > > > (r'^product/$', views.add_product), > > (r'^product/$', views.add_product_details), > > This has no chance of doing what you expect. Only one view function will > be called for a single request. If you want to pass two form objects to > the template, you need to do it from the same view function. You can > still put the form creation pieces in separate functions, but your view > function will have to call both of them and combine the results into a > context to pass to a template. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
On Thu, 2008-11-20 at 14:03 -0800, ayayalar wrote: [...] > URLS > urlpatterns = patterns('', > > (r'^product/$', views.add_product), > (r'^product/$', views.add_product_details), This has no chance of doing what you expect. Only one view function will be called for a single request. If you want to pass two form objects to the template, you need to do it from the same view function. You can still put the form creation pieces in separate functions, but your view function will have to call both of them and combine the results into a context to pass to a template. Regards, Malcolm --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
On Thu, Nov 20, 2008 at 5:03 PM, ayayalar <[EMAIL PROTECTED]> wrote: > > VIEW: > > def add_product(request): >if not request.method == 'POST': >form1 = ProductForm() >return render_to_response('index.html', {'form1' : form1}) >else: >form1 = ProductForm(request.POST) >if form1.is_valid(): >form1.save() >return HttpResponseRedirect('/thanks.html') > > > def add_product_details(request): >if not request.method == 'POST': >form2 = ProductDetailForm() >return render_to_response('index.html', {'form2' : form2}) >else: >if form2.is_valid(): >form2.save() >return HttpResponseRedirect('/thanks.html') > > URLS > urlpatterns = patterns('', > >(r'^product/$', views.add_product), >(r'^product/$', views.add_product_details), > > > Is this possible? For some reason the 2nd form never shows up > A request is going to match only one url pattern (assuming a match is found). You seem to be expecting that one request will first match the first (add_product) view you have specified and then when that is done the 2nd (add_product_details) one will get called. That's not how it works. If you wont both the code that is in add_product and add_product_details to be called for your r'^product/$' url, then you need to combine their code into one function that you specify in a single urlentry for r^product/$'. In that combined view you need to create both forms and pass both of them in the context to your template. Karen --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
Yes but you never pass two forms to the template at the same time. In add_product you pass form1, in add_product_details you pass form2. >>> (r'^product/$', views.add_product), >>> (r'^product/$', views.add_product_details), You have the same URL twice, only one of them will ever be active. Remove one of those of URL's, then merge the two views together and pass both form1 and form2 to the template. -- Andy McKay Clearwind Consulting Site: www.clearwind.ca Blog: www.agmweb.ca/blog/andy --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
And I do that. Here is my template: {{ form1.as_table }} {{ form2.as_table }} On Nov 20, 2:15 pm, Brian Neal <[EMAIL PROTECTED]> wrote: > On Nov 20, 4:03 pm, ayayalar <[EMAIL PROTECTED]> wrote: > > > > > VIEW: > > > def add_product(request): > > if not request.method == 'POST': > > form1 = ProductForm() > > return render_to_response('index.html', {'form1' : form1}) > > else: > > form1 = ProductForm(request.POST) > > if form1.is_valid(): > > form1.save() > > return HttpResponseRedirect('/thanks.html') > > > def add_product_details(request): > > if not request.method == 'POST': > > form2 = ProductDetailForm() > > return render_to_response('index.html', {'form2' : form2}) > > else: > > if form2.is_valid(): > > form2.save() > > return HttpResponseRedirect('/thanks.html') > > > URLS > > urlpatterns = patterns('', > > > (r'^product/$', views.add_product), > > (r'^product/$', views.add_product_details), > > > Is this possible? For some reason the 2nd form never shows up > > Well you need to pass both forms to the template to get them both to > show up. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to display multiple forms in a single template file?
On Nov 20, 4:03 pm, ayayalar <[EMAIL PROTECTED]> wrote: > VIEW: > > def add_product(request): > if not request.method == 'POST': > form1 = ProductForm() > return render_to_response('index.html', {'form1' : form1}) > else: > form1 = ProductForm(request.POST) > if form1.is_valid(): > form1.save() > return HttpResponseRedirect('/thanks.html') > > def add_product_details(request): > if not request.method == 'POST': > form2 = ProductDetailForm() > return render_to_response('index.html', {'form2' : form2}) > else: > if form2.is_valid(): > form2.save() > return HttpResponseRedirect('/thanks.html') > > URLS > urlpatterns = patterns('', > > (r'^product/$', views.add_product), > (r'^product/$', views.add_product_details), > > Is this possible? For some reason the 2nd form never shows up Well you need to pass both forms to the template to get them both to show up. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Is it possible to display multiple forms in a single template file?
VIEW: def add_product(request): if not request.method == 'POST': form1 = ProductForm() return render_to_response('index.html', {'form1' : form1}) else: form1 = ProductForm(request.POST) if form1.is_valid(): form1.save() return HttpResponseRedirect('/thanks.html') def add_product_details(request): if not request.method == 'POST': form2 = ProductDetailForm() return render_to_response('index.html', {'form2' : form2}) else: if form2.is_valid(): form2.save() return HttpResponseRedirect('/thanks.html') URLS urlpatterns = patterns('', (r'^product/$', views.add_product), (r'^product/$', views.add_product_details), Is this possible? For some reason the 2nd form never shows up --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---