Sunday, September 26, 2010

Re: problem with saving a form



On Sun, Sep 26, 2010 at 8:51 PM, Marc Aymerich <glicerinu@gmail.com> wrote:
I'm trying to make a ModelForm in order to edit an existing object of the class 'member'. So I followed this documentation:


  # 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-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