Re: problem with saving a form
On Sun, Sep 26, 2010 at 8:51 PM, Marc Aymerich wrote: > I'm trying to make a ModelForm in order to edit an existing object of the > class 'member'. So I followed this documentation: > > > http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method > > > # Create a form to edit an existing Article. > >>> a = Article.objects.get(pk=1) > >>> f = ArticleForm(instance=a) > >>> f.save() > > > The form is displayed correctly, however it doesn't work properly, as it > does not save the data neither validate the fields (for instance it does not > check the e-mail is an e-mail). It doesn't report any error though, so im > not sure what could have gone wrong. > Can anyone enlighten me? > > This is my view: > > @login_required() > def edit_member(request): > """ edit member information """ > > Member=member.objects.get(id=request.user.id) > title = "Edit member " + Member.name > > if request.method == 'POST': > form = MemberForm(request.POST, instance=Member) > if form.is_valid(): > form.save() > return HttpResponseRedirect(reverse('list_member')) > else: > form = MemberForm(instance=Member) > > if request.user.is_authenticated(): > return render_to_response('generic_form.html', locals(), > context_instance=RequestContext(request)) > return render_to_response('list_member.html', locals()) > It seems that the condition request.method == 'POST' is never true :( whyy?? -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: problem with saving a form
On Sun, Sep 26, 2010 at 4:15 PM, Marc Aymerich wrote: > It seems that the condition request.method == 'POST' is never true :( > whyy?? What does the template that contains the form look like? Karen -- http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: problem with saving a form
On Sun, Sep 26, 2010 at 10:34 PM, Karen Tracey wrote: > On Sun, Sep 26, 2010 at 4:15 PM, Marc Aymerich wrote: > >> It seems that the condition request.method == 'POST' is never true :( >> whyy?? > > > What does the template that contains the form look like? > > Hi Karen, Here the template: {% extends "base.html" %} {% block title %}Domain Section{% endblock %} {% block content %} {{ title }} {% csrf_token %} {{ form.as_table }} {% endblock %} I use it succesfully with others forms. > Karen > -- > http://tracey.org/kmt/ > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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. > -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: problem with saving a form
On Sun, Sep 26, 2010 at 10:15 PM, Marc Aymerich wrote: > > > On Sun, Sep 26, 2010 at 8:51 PM, Marc Aymerich wrote: > >> I'm trying to make a ModelForm in order to edit an existing object of the >> class 'member'. So I followed this documentation: >> >> >> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method >> >> >> # Create a form to edit an existing Article. >> >>> a = Article.objects.get(pk=1) >> >>> f = ArticleForm(instance=a) >> >>> f.save() >> >> >> The form is displayed correctly, however it doesn't work properly, as it >> does not save the data neither validate the fields (for instance it does not >> check the e-mail is an e-mail). It doesn't report any error though, so im >> not sure what could have gone wrong. >> Can anyone enlighten me? >> >> This is my view: >> >> @login_required() >> def edit_member(request): >> """ edit member information """ >> >> Member=member.objects.get(id=request.user.id) >> title = "Edit member " + Member.name >> >> if request.method == 'POST': >> form = MemberForm(request.POST, instance=Member) >> if form.is_valid(): >> form.save() >> return HttpResponseRedirect(reverse('list_member')) >> else: >> form = MemberForm(instance=Member) >> >> if request.user.is_authenticated(): >> return render_to_response('generic_form.html', locals(), >> context_instance=RequestContext(request)) >> return render_to_response('list_member.html', locals()) >> > > > It seems that the condition request.method == 'POST' is never true :( > whyy?? > > > I tried with a generic view, but it does not save the object nor validates the form :( just redirect to post_save_redirect. return update_object(request, form_class=MemberForm, object_id=request.user.member.id, template_name='generic_form.html', post_save_redirect=reverse('list_member'), extra_context=dict(title="Edit Memmber " ), login_required=True,) -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: problem with saving a form
You're just all around doing it wrong. A ModelForm is used so that you don't have to individually list all the fields you need, it is based off the model. What is the code for your Model? And also, I'd reread the form reference from the start. On Sep 26, 5:25 pm, Marc Aymerich wrote: > On Sun, Sep 26, 2010 at 10:15 PM, Marc Aymerich wrote: > > > On Sun, Sep 26, 2010 at 8:51 PM, Marc Aymerich wrote: > > >> I'm trying to make a ModelForm in order to edit an existing object of the > >> class 'member'. So I followed this documentation: > > >>http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav... > > >> # Create a form to edit an existing Article. > >> >>> a = Article.objects.get(pk=1) > >> >>> f = ArticleForm(instance=a) > >> >>> f.save() > > >> The form is displayed correctly, however it doesn't work properly, as it > >> does not save the data neither validate the fields (for instance it does > >> not > >> check the e-mail is an e-mail). It doesn't report any error though, so im > >> not sure what could have gone wrong. > >> Can anyone enlighten me? > > >> This is my view: > > >> @login_required() > >> def edit_member(request): > >> """ edit member information """ > > >> Member=member.objects.get(id=request.user.id) > >> title = "Edit member " + Member.name > > >> if request.method == 'POST': > >> form = MemberForm(request.POST, instance=Member) > >> if form.is_valid(): > >> form.save() > >> return HttpResponseRedirect(reverse('list_member')) > >> else: > >> form = MemberForm(instance=Member) > > >> if request.user.is_authenticated(): > >> return render_to_response('generic_form.html', locals(), > >> context_instance=RequestContext(request)) > >> return render_to_response('list_member.html', locals()) > > > It seems that the condition request.method == 'POST' is never true :( > > whyy?? > > I tried with a generic view, but it does not save the object nor validates > the form :( just redirect to post_save_redirect. > > return update_object(request, > form_class=MemberForm, > object_id=request.user.member.id, > template_name='generic_form.html', > post_save_redirect=reverse('list_member'), > extra_context=dict(title="Edit Memmber " ), > login_required=True,) > -- > Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.