I am a fresher in django(version - 1.10). I am using allauth app in the 
frontend for registration.

I am getting an error in the frontend while signing up.

        assert not EmailAddress.objects.filter(user=user).exists()
    AssertionError


https://github.com/pennersr/django-allauth/blob/master/allauth/account/utils.py#L251

`models.py` looks like this

    class EmailAddress(models.Model):
        user = models.OneToOneField(User, unique=True, related_name =
'address')
        email = models.EmailField()
        verified = models.BooleanField(verbose_name=_('verified'), default=
True)
        primary = models.BooleanField(verbose_name=_('primary'), default=
True)
    
        class Meta:
            db_table = 'account_emailaddress'
    
    
    class UserProfile(models.Model, HashedPk):
        user = models.OneToOneField(User, unique=True, related_name =
'profile')
        job_title = models.CharField(max_length=128, blank=True, null=False, 
default="")
        website = models.URLField(max_length=255, blank=True, null=True)
        organisation = models.CharField(max_length=50, blank=True, null=True
, default="")
        phone_number = PhoneNumberField( blank=True, null=True)
    
    
    @receiver(post_save, sender=User)
    def create_profile(sender, instance, created, **kwargs):
        if created:
            UserProfile.objects.create(user=instance)
            EmailAddress.objects.create(user=instance, email=instance.email)


As far as I can understand that `EmailAddress.objects.create` a row in 
`emailaddress` table with the email,id etc and then `allauth` tries to 
create a row with the same email,id.

I had to save email in emailaddress table because there is no need to 
confirm email if the user is added by the admin.

Is there any way so that if the user is added by the admin then run the 
below line else ignore.

    EmailAddress.objects.create(user=instance, email=instance.email)



Also is there any alternative way to create the emailaddress object from 
admin.py using django admin save_model method

Any help or suggestion is highly appreciated.


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/28981ac8-1cfb-428b-a2fc-f34263aa75d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to