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())


and this is the form definition:

from django.contrib.localflavor.es.forms import *
from django.contrib.localflavor.es.es_provinces import PROVINCE_CHOICES

class MemberForm(ModelForm):
    cifnif = ESIdentityCardNumberField()
    phone = ESPhoneNumberField()
    phone2 = ESPhoneNumberField()
    fax = ESPhoneNumberField()
    province = forms.ChoiceField(choices=PROVINCE_CHOICES)
    zipcode = ESPostalCodeField()

    class Meta:
        model = member

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

Reply via email to