Django and Custom Form validation -


I am trying to create and close a custom form field. This version of the Django is 1.0.

This is my form object

  class UsernameField (forms.CharField): def clean (auto, value): print ""  
< P> How do I call here

Register Form (forms.Form): username = UsernameField (max_length = 30, min_length = 4) password = forms.CharField (Widget = forms.PasswordInput ), Min_length = 5) password2 = forms.CharField (widget = forms.PasswordInput (), min_length = 5) Email = forms.EmailField (max_length = 75)

Now I'm in a nail You want to keep the default min / max_length check for CharField .. But I do not think how to do it

If I want to put any code He puts the graph () if they are not Czech. If I try to call parents Kalan () I get an error

If you want to clean your area, There is no need to define the area, you can do this in the clean_username name of the form

  class RegisterForm (forms.Form): username = forms.CharField (max_length = 30, Min_length = 4) ... def def_username (self): user name = self.cleaned_data ['user name]] try: user = user.objects.get (user name = username) Odkr User.DoesNotExist: Create back username formula. ValidationError (U '% s already exists'% username) def clean (self): # here you will check the password ...  

You also use Django for user registration It can take care of it in a pluggable app, which will allow all user recognition, build and setup for you.

For the creation of new firld, the clean () method of your field should return a clean value, or print it.

  Class MyField (forms D): def clean (self, value): # return the return value  

Comments