On Mon, Feb 2, 2009 at 11:35 PM, vierda <m...@pensil.com> wrote:
>
> Hi all, I have three forms and none of these forms pass is_valid()
> test when I test in intrepeter. kindly help for point out what's
> problem with my forms. thank you.
>
> from django.contrib.auth.models import User
> from django.contrib.auth.forms import UserCreationForm
> from django import forms
> from django.forms import ModelForm
>
> #1st
> class RegistrationForm(UserCreationForm):
>   email = forms.EmailField(label=("e-mail"))
>
>   class Meta:
>      model = User
>      fields = ('username', 'email','password2')
>
>   def clean_email(self):
>        email = self.cleaned_data["email"]
>        try:
>            User.objects.get(email=email)
>        except User.DoesNotExist:
>            return email
>        raise forms.ValidationError(("e-mail already exist."))
>
> #2nd
> class UserProfileForm(ModelForm):
>   class Meta :
>   model = User
>      fields = ('email',)
>
> #3rd
> class DeleteForm(ModelForm):
>   class Meta :
>      model = User
>      fields = ('username',)

Wait. Do you know what "is_valid()" do, right?. :-)

is_valid refers to data sent to the form (for example request.POST),
not form itself.

For instance:

>>> f = UserProfileForm({'email':'a'})
>>> f.is_valid()
False
>>> f.errors
{'email': [u'Enter a valid e-mail address.']}

But:

>>> f = UserProfileForm({'email':'a...@a.com'})
>>> f.is_valid()
True

M

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

Reply via email to