List Info

Thread: New Forms + Validation




New Forms + Validation
user name
2007-01-31 06:19:27
I have a form where a user needs to enter a 8 digit code.  
I want to
check the user's input against a database and return an
error if the
code has already been entered by another user.

 If I use New Forms,  do I need to write a custom Field to
do this
validation?
Any pointers would be appreciated.

Many thanks

MerMer


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: New Forms + Validation
user name
2007-01-31 07:10:02
On Jan 31, 1:19 pm, "MerMer" <merr...googlemail.com> wrote:
> I have a form where a user needs to enter a 8 digit
code.   I want to
> check the user's input against a database and return an
error if the
> code has already been entered by another user.
>
>  If I use New Forms,  do I need to write a custom Field
to do this
> validation?

No, just implement your clean_YOURFIELDNAME method of the
form.

class Person(Form):
... (fields declaration follow)

    def clean_student_seniority(self):
        if (self.clean_data.get("person_type") ==
1) and
(self.clean_data.get("student_seniority") ==
None):
            raise ValidationError(u"Students must have
a seniority
defined")

        return
self.clean_data["student_seniority"]

Then in your view you check if form.is_valid()

Lorenzo


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )