Hello again,

In extended auth user model, is there any *way to handle unique fields with 
django forms*. 

Lets say I have model like:

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    phone_num = models.BigIntegerField(null=True, unique=True)

    def __unicode__(self):
    return "%s" % self.user


so how can a user gets an error message if the phone number already exist?
Is there any django way to handle this??


On Wednesday, April 17, 2013 12:58:46 PM UTC+5:30, sachin wrote:
>
> Thanx,
>
> Btw, I solved it by creating an instance of get_profile() and then saving 
> user and profile separately.
>
> here is the code snippet of *forms.py* 
>
> if commit:
>         profile = user.get_profile()
>         profile.serial_num = self.cleaned_data['serial_num']
>         profile.save()
>         user.save()
>  return user, profile
>
>
>
>
>
> On Wed, Apr 17, 2013 at 11:09 AM, Avnesh Shakya <[email protected]>wrote:
>
>> This error is occur when you're saving the member, not the user. When 
>> creating the member, you are not assigning the user.
>>
>>
>> On Wed, Apr 17, 2013 at 10:45 AM, sachin <[email protected]> wrote:
>>
>>> I m still stuck with 
>>>
>>> Exception Type:     IntegrityError
>>> Exception Value:     column user_id is not unique
>>>
>>> Whenever I try to save, it throws the above error.
>>>
>>> I have attached files for reference, can someone help ??
>>>
>>>
>>>
>>> On Saturday, April 6, 2013 7:07:32 PM UTC+5:30, sachin wrote:
>>>>
>>>> Thanx Shawn,
>>>> *
>>>> *
>>>> UserCreationForm really helped.
>>>>
>>>> Now I have a different problem, I'm trying to add custom feilds to *auth 
>>>> user *using 
>>>> storing-additional-**information-about-users<https://docs.djangoproject.com/en/1.4/topics/auth/#storing-additional-information-about-users>
>>>> .
>>>> But now I m getting this error.
>>>>
>>>> Exception Type:IntegrityError Exception Value:
>>>>
>>>> column user_id is not unique
>>>>
>>>>
>>>>
>>>> This is my *models.py *file:
>>>> *
>>>> *
>>>> from django.db import models
>>>> from django.contrib.auth.models import User
>>>> from django.db.models.signals import post_save
>>>>
>>>> class UserProfile(models.Model):
>>>>     user = models.OneToOneField(User)
>>>>     sr_no = models.CharField(max_length=**10)
>>>>
>>>>     def __unicode__(self):
>>>>         return self.sr_no
>>>>
>>>> def create_user_profile(sender, instance, created, **kwargs):
>>>>     if created:
>>>>         UserProfile.objects.create(**user=instance)
>>>>
>>>> post_save.connect(create_user_**profile, sender=User)
>>>>
>>>> I have added *unique *field, but it does not make any difference. So 
>>>> far I haven't got
>>>> any convincing answer. 
>>>>
>>>> Any Idea ??
>>>> On Tuesday, April 2, 2013 12:49:52 AM UTC+5:30, Shawn Milochik wrote:
>>>>>
>>>>> Don't even worry about factories. They're for when you want a bunch of 
>>>>> forms for the same model on the page at once. 
>>>>>
>>>>> Use the UserCreationForm in django.contrib.auth.forms. It only accepts 
>>>>> a username and password, so you can either subclass it to add the 
>>>>> fields or make your own form and add it to your view so that they both 
>>>>> appear in the same HTML form. You can validate both and do what you 
>>>>> need to do. 
>>>>>
>>>>> You definitely shouldn't be writing validation logic for the password 
>>>>> and username and such -- that's what ModelForms are for. 
>>>>>
>>>>> If you have more specific questions just ask. 
>>>>>
>>>>  -- 
>>> 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 [email protected].
>>>
>>> To post to this group, send email to [email protected].
>>> 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/8PHPgI4i4sQ/unsubscribe?hl=en
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected].
>> To post to this group, send email to [email protected].
>> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to