Thursday, April 25, 2013

Re: handling IntegrityError: Duplicate entry in UserCreationForm

hi Sachin,

Please use django's form clean method in order to validate your phone_num field.
You can also override the django's clean method by using your own clean_phone_field method.
Please refer the link:-

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

I am sure that a small googling on overriding the clean method in django form class will defiantly help you.

-Siddharth


On Wed, Apr 24, 2013 at 8:57 PM, sachin <iclcoolster@gmail.com> wrote:
Hello,

I m extending my auth user model to add addition entries like phone numbers and emp_id. In the model I m marking both the fields as unique=True.
Form generation is using UserCreationForm. But whenever I try to save same phone number or emp_id it throws

IntegrityError: (1062, "Duplicate entry '447' for key 'phone_num'")

How to handle this error and show it to user during form input?

Also how do the same UserCreationForm validates duplicate entry for username etc ??

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment