Re: Submitting a form
Thank you On 30 July, 00:04, Adam Yee wrote: > Use the model's verbose field > namehttp://docs.djangoproject.com/en/dev/topics/db/models/#id2 > > On Jul 29, 3:55 pm, When ideas fail wrote: > > > Is there a way i can change the label for a field in the model form? > > > On 29 July, 21:44, When ideas fail wrote: > > > > Ok thanks seems to work now. > > > > On 29 July, 21:27, Daniel Roseman wrote: > > > > > On Jul 29, 9:17 pm, When ideas fail wrote: > > > > > > I've created a model form and I was wondering what the correct way to > > > > > save this was. I've tried adapting the view from the standard django > > > > > forms docs but maybe it should be different? > > > > > > This is what i have in my view (it says contact form but its a form > > > > > that should save contacts in a db): > > > > > > class ContactForm(ModelForm): > > > > > class Meta: > > > > > model = Contact > > > > > > def contact_view(request): > > > > > if request.method == 'Post': > > > > > form = ContactForm(request.POST) > > > > > if form.is_valid(): > > > > > contact= form.save() > > > > > return HttpResponseRedirect('/thanks/') > > > > > else: return HttpResponseRedirect('/error/') > > > > > > else: > > > > > form = ContactForm() > > > > > tags = Tag.objects.all() > > > > > return render_to_response('Site/contact.html', locals(), > > > > > context_instance=RequestContext(request)) > > > > > > And my template is like this: > > > > > > > > > > > {{ form.as_p }} > > > > > > > > > value="Submit" /> > > > > > > My understanding is that with this setup it should go to thanks/ if > > > > > the form is valid and error/ if it is not and it doesn't do either, > > > > > and it doesn't save or come back with any errors either . could > > > > > someone help me please? > > > > > > Thanks > > > > > There are two problems, but the main one is in the first line of your > > > > view. request.method == 'Post' will *never* be true, because the > > > > method (as in shown in your template) is all upper case. > > > > request.method == 'POST' should work. > > > > > Secondly, don't redirect to /error/. Drop that else clause altogether, > > > > and let the view fall through to the final render_to_response. This > > > > will redisplay the form with any errors. > > > > -- > > > > DR.- Hide quoted text - > > > - Show quoted text - --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Submitting a form
Use the model's verbose field name http://docs.djangoproject.com/en/dev/topics/db/models/#id2 On Jul 29, 3:55 pm, When ideas fail wrote: > Is there a way i can change the label for a field in the model form? > > On 29 July, 21:44, When ideas fail wrote: > > > > > Ok thanks seems to work now. > > > On 29 July, 21:27, Daniel Roseman wrote: > > > > On Jul 29, 9:17 pm, When ideas fail wrote: > > > > > I've created a model form and I was wondering what the correct way to > > > > save this was. I've tried adapting the view from the standard django > > > > forms docs but maybe it should be different? > > > > > This is what i have in my view (it says contact form but its a form > > > > that should save contacts in a db): > > > > > class ContactForm(ModelForm): > > > > class Meta: > > > > model = Contact > > > > > def contact_view(request): > > > > if request.method == 'Post': > > > > form = ContactForm(request.POST) > > > > if form.is_valid(): > > > > contact= form.save() > > > > return HttpResponseRedirect('/thanks/') > > > > else: return HttpResponseRedirect('/error/') > > > > > else: > > > > form = ContactForm() > > > > tags = Tag.objects.all() > > > > return render_to_response('Site/contact.html', locals(), > > > > context_instance=RequestContext(request)) > > > > > And my template is like this: > > > > > > > > > {{ form.as_p }} > > > > > > > value="Submit" /> > > > > > My understanding is that with this setup it should go to thanks/ if > > > > the form is valid and error/ if it is not and it doesn't do either, > > > > and it doesn't save or come back with any errors either . could > > > > someone help me please? > > > > > Thanks > > > > There are two problems, but the main one is in the first line of your > > > view. request.method == 'Post' will *never* be true, because the > > > method (as in shown in your template) is all upper case. > > > request.method == 'POST' should work. > > > > Secondly, don't redirect to /error/. Drop that else clause altogether, > > > and let the view fall through to the final render_to_response. This > > > will redisplay the form with any errors. > > > -- > > > DR.- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Submitting a form
Is there a way i can change the label for a field in the model form? On 29 July, 21:44, When ideas fail wrote: > Ok thanks seems to work now. > > On 29 July, 21:27, Daniel Roseman wrote: > > > On Jul 29, 9:17 pm, When ideas fail wrote: > > > > I've created a model form and I was wondering what the correct way to > > > save this was. I've tried adapting the view from the standard django > > > forms docs but maybe it should be different? > > > > This is what i have in my view (it says contact form but its a form > > > that should save contacts in a db): > > > > class ContactForm(ModelForm): > > > class Meta: > > > model = Contact > > > > def contact_view(request): > > > if request.method == 'Post': > > > form = ContactForm(request.POST) > > > if form.is_valid(): > > > contact= form.save() > > > return HttpResponseRedirect('/thanks/') > > > else: return HttpResponseRedirect('/error/') > > > > else: > > > form = ContactForm() > > > tags = Tag.objects.all() > > > return render_to_response('Site/contact.html', locals(), > > > context_instance=RequestContext(request)) > > > > And my template is like this: > > > > > > > {{ form.as_p }} > > > > > value="Submit" /> > > > > My understanding is that with this setup it should go to thanks/ if > > > the form is valid and error/ if it is not and it doesn't do either, > > > and it doesn't save or come back with any errors either . could > > > someone help me please? > > > > Thanks > > > There are two problems, but the main one is in the first line of your > > view. request.method == 'Post' will *never* be true, because the > > method (as in shown in your template) is all upper case. > > request.method == 'POST' should work. > > > Secondly, don't redirect to /error/. Drop that else clause altogether, > > and let the view fall through to the final render_to_response. This > > will redisplay the form with any errors. > > -- > > DR. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Submitting a form
Is there a way i can change the label for a field in the model form? On 29 July, 21:44, When ideas fail wrote: > Ok thanks seems to work now. > > On 29 July, 21:27, Daniel Roseman wrote: > > > On Jul 29, 9:17 pm, When ideas fail wrote: > > > > I've created a model form and I was wondering what the correct way to > > > save this was. I've tried adapting the view from the standard django > > > forms docs but maybe it should be different? > > > > This is what i have in my view (it says contact form but its a form > > > that should save contacts in a db): > > > > class ContactForm(ModelForm): > > > class Meta: > > > model = Contact > > > > def contact_view(request): > > > if request.method == 'Post': > > > form = ContactForm(request.POST) > > > if form.is_valid(): > > > contact= form.save() > > > return HttpResponseRedirect('/thanks/') > > > else: return HttpResponseRedirect('/error/') > > > > else: > > > form = ContactForm() > > > tags = Tag.objects.all() > > > return render_to_response('Site/contact.html', locals(), > > > context_instance=RequestContext(request)) > > > > And my template is like this: > > > > > > > {{ form.as_p }} > > > > > value="Submit" /> > > > > My understanding is that with this setup it should go to thanks/ if > > > the form is valid and error/ if it is not and it doesn't do either, > > > and it doesn't save or come back with any errors either . could > > > someone help me please? > > > > Thanks > > > There are two problems, but the main one is in the first line of your > > view. request.method == 'Post' will *never* be true, because the > > method (as in shown in your template) is all upper case. > > request.method == 'POST' should work. > > > Secondly, don't redirect to /error/. Drop that else clause altogether, > > and let the view fall through to the final render_to_response. This > > will redisplay the form with any errors. > > -- > > DR. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Submitting a form
Ok thanks seems to work now. On 29 July, 21:27, Daniel Roseman wrote: > On Jul 29, 9:17 pm, When ideas fail wrote: > > > > > I've created a model form and I was wondering what the correct way to > > save this was. I've tried adapting the view from the standard django > > forms docs but maybe it should be different? > > > This is what i have in my view (it says contact form but its a form > > that should save contacts in a db): > > > class ContactForm(ModelForm): > > class Meta: > > model = Contact > > > def contact_view(request): > > if request.method == 'Post': > > form = ContactForm(request.POST) > > if form.is_valid(): > > contact= form.save() > > return HttpResponseRedirect('/thanks/') > > else: return HttpResponseRedirect('/error/') > > > else: > > form = ContactForm() > > tags = Tag.objects.all() > > return render_to_response('Site/contact.html', locals(), > > context_instance=RequestContext(request)) > > > And my template is like this: > > > > > {{ form.as_p }} > > > /> > > > My understanding is that with this setup it should go to thanks/ if > > the form is valid and error/ if it is not and it doesn't do either, > > and it doesn't save or come back with any errors either . could > > someone help me please? > > > Thanks > > There are two problems, but the main one is in the first line of your > view. request.method == 'Post' will *never* be true, because the > method (as in shown in your template) is all upper case. > request.method == 'POST' should work. > > Secondly, don't redirect to /error/. Drop that else clause altogether, > and let the view fall through to the final render_to_response. This > will redisplay the form with any errors. > -- > DR. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Submitting a form
On Jul 29, 9:17 pm, When ideas fail wrote: > I've created a model form and I was wondering what the correct way to > save this was. I've tried adapting the view from the standard django > forms docs but maybe it should be different? > > This is what i have in my view (it says contact form but its a form > that should save contacts in a db): > > class ContactForm(ModelForm): > class Meta: > model = Contact > > def contact_view(request): > if request.method == 'Post': > form = ContactForm(request.POST) > if form.is_valid(): > contact= form.save() > return HttpResponseRedirect('/thanks/') > else: return HttpResponseRedirect('/error/') > > else: > form = ContactForm() > tags = Tag.objects.all() > return render_to_response('Site/contact.html', locals(), > context_instance=RequestContext(request)) > > And my template is like this: > > > {{ form.as_p }} > > > My understanding is that with this setup it should go to thanks/ if > the form is valid and error/ if it is not and it doesn't do either, > and it doesn't save or come back with any errors either . could > someone help me please? > > Thanks There are two problems, but the main one is in the first line of your view. request.method == 'Post' will *never* be true, because the method (as in shown in your template) is all upper case. request.method == 'POST' should work. Secondly, don't redirect to /error/. Drop that else clause altogether, and let the view fall through to the final render_to_response. This will redisplay the form with any errors. -- DR. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---