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()


`models.py` looks like this

    class EmailAddress(models.Model):
        user = models.OneToOneField(User, unique=True, related_name =
        email = models.EmailField()
        verified = models.BooleanField(verbose_name=_('verified'), default=
        primary = models.BooleanField(verbose_name=_('primary'), default=
        class Meta:
            db_table = 'account_emailaddress'
    class UserProfile(models.Model, HashedPk):
        user = models.OneToOneField(User, unique=True, related_name =
        job_title = models.CharField(max_length=128, blank=True, null=False, 
        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:
            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 
For more options, visit https://groups.google.com/d/optout.

Reply via email to