On Fri, 2008-11-21 at 10:28 +0100, Florencio Cano wrote:
> Hello all,
> I have two models called User and Responsible. When I add a
> Responsible automatically a User is added. I have only one form to add
> a User and a Responsible.
> 
> class NewUserResponsibleForm(forms.Form):
>     username = forms.CharField(max_length=30)
>     password = forms.CharField(max_length=20, widget=forms.PasswordInput())
>     confirm_password = forms.CharField(max_length=20,
> widget=forms.PasswordInput())
>     email = forms.EmailField(max_length=30)
>     name = forms.CharField(max_length=64)
>     responsible_boss = forms.BooleanField(required=False)
> 
> With the username and the password a User will be created. With the
> others fields a Responsible will be created.
> The problem is that I want to check that the username is unique and if
> it is not, show the error in this form. If I check this form with
> is_valid() the username is not checked against User and I can't use
> the attribute unique=True in forms.Form.

All you need to do is write a clean_username() method that does the
validation you need. You can do any sort of custom checking on a form
field that you like by writing such a method. The documentation for this
is at 

http://docs.djangoproject.com/en/dev/ref/forms/validation/

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to