Re: handling IntegrityError: Duplicate entry in UserCreationForm
hey guys, got the solution: for each field to validate, I wrote a validate function: code snippet: def clean_: try: UserProfile.objects.get(phone_num=self.cleaned_data['']) except UserProfile.DoesNotExist: return self.cleaned_data[""] raise forms.ValidationError(("FIELD VALUE already exist")) On Sat, Apr 27, 2013 at 6:41 PM, isachin wrote: > @ Kelly: thank you very much for pointing me to django's source code. > > Yes I got that validation done and applied the same code for validation. > Below is the snippet : > >profile.serial_num = self.cleaned_data['phone_num'] > try: > profile._default_manager.get(phone_num=profile.serial_num) > except UserProfile.DoesNotExist: > profile.serial_num = profile.phone_num > raise forms.ValidationError("Phone number already exist") > > @ all > > Now the next problem is, similar snippet appears in > > */site-packages/django/contrib/auth/forms.py* > > throws an error in the template form itself, but my code only shows up > error in django's traceback, how can I bring it to front ? > so that as soon as one fills phone number field it and press *submit, *it > should say 'Phone number already exist'. > > m I doing wrong in using UserCreationForm ? or UserProfile. I m using > user.get_profile() for profile fields. > > > > On Thu, Apr 25, 2013 at 7:09 PM, Kelly Nicholes wrote: > >> If you ever want to know how the UserCreationForm works, the source is >> always available not only on your machine but also on >> https://github.com/django/django/blob/master/django/contrib/auth/models.py >> >> >> On Wednesday, April 24, 2013 9:27:39 AM UTC-6, sachin 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 a topic in the >> Google Groups "Django users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/django-users/EaYF9DEptLo/unsubscribe?hl=en >> . >> To unsubscribe from this group and all its topics, send an email to >> django-users+unsubscr...@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. >> >> >> > > > > -- > Sachin > -- Sachin -- 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+unsubscr...@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.
Re: handling IntegrityError: Duplicate entry in UserCreationForm
@ Kelly: thank you very much for pointing me to django's source code. Yes I got that validation done and applied the same code for validation. Below is the snippet : profile.serial_num = self.cleaned_data['phone_num'] try: profile._default_manager.get(phone_num=profile.serial_num) except UserProfile.DoesNotExist: profile.serial_num = profile.phone_num raise forms.ValidationError("Phone number already exist") @ all Now the next problem is, similar snippet appears in */site-packages/django/contrib/auth/forms.py* throws an error in the template form itself, but my code only shows up error in django's traceback, how can I bring it to front ? so that as soon as one fills phone number field it and press *submit, *it should say 'Phone number already exist'. m I doing wrong in using UserCreationForm ? or UserProfile. I m using user.get_profile() for profile fields. On Thu, Apr 25, 2013 at 7:09 PM, Kelly Nicholes wrote: > If you ever want to know how the UserCreationForm works, the source is > always available not only on your machine but also on > https://github.com/django/django/blob/master/django/contrib/auth/models.py > > > On Wednesday, April 24, 2013 9:27:39 AM UTC-6, sachin 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 a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/EaYF9DEptLo/unsubscribe?hl=en > . > To unsubscribe from this group and all its topics, send an email to > django-users+unsubscr...@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. > > > -- Sachin -- 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+unsubscr...@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.
Re: handling IntegrityError: Duplicate entry in UserCreationForm
If you ever want to know how the UserCreationForm works, the source is always available not only on your machine but also on https://github.com/django/django/blob/master/django/contrib/auth/models.py On Wednesday, April 24, 2013 9:27:39 AM UTC-6, sachin 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+unsubscr...@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.
Re: handling IntegrityError: Duplicate entry in UserCreationForm
Thanx Siddharth and Pradeep, I will try both suggestion and let you know On Thu, Apr 25, 2013 at 2:07 PM, Pradeep Kumar wrote: > Hi Sachin, > > If you have added the unique=True later and migrated the existing table, I > would also suggest you to first clean up the NULL and duplicate entries > using a script or even from shell. > > After doing that you can use > * try: * > # your code here > * except IntegrityError: * > #create variables here to send user error message > > One more pointer - try checking for the user input( X.object.filter > method) in the unique fields in database before performing .save > > > On Thu, Apr 25, 2013 at 1:34 PM, Siddharth Ghumre < > siddharth.ghumr...@gmail.com> wrote: > >> 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 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+unsubscr...@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+unsubscr...@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 a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/EaYF9DEptLo/unsubscribe?hl=en > . > To unsubscribe from this group and all its topics, send an email to > django-users+unsubscr...@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. > > > -- Sachin -- 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+unsubscr...@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.
Re: handling IntegrityError: Duplicate entry in UserCreationForm
Hi Sachin, If you have added the unique=True later and migrated the existing table, I would also suggest you to first clean up the NULL and duplicate entries using a script or even from shell. After doing that you can use * try: * # your code here * except IntegrityError: * #create variables here to send user error message One more pointer - try checking for the user input( X.object.filter method) in the unique fields in database before performing .save On Thu, Apr 25, 2013 at 1:34 PM, Siddharth Ghumre < siddharth.ghumr...@gmail.com> wrote: > 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 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+unsubscr...@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+unsubscr...@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+unsubscr...@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.
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 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+unsubscr...@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+unsubscr...@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.
handling IntegrityError: Duplicate entry in UserCreationForm
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+unsubscr...@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.