All good. It works now.
It has to be EmailAddress.objects.create(user=instance, email=instance.email
Many thanks for your input.
On Saturday, 12 August 2017 16:58:10 UTC+1, Derek wrote:
> I am not exactly sure about your use case description, but it seems as if
> your EmailAddress table is incomplete - suggest:
> class EmailAddress(models.Model):
> user = models.OneToOneField(User, unique=True, related_name ='profile'
> verified = models.BooleanField(verbose_name=_('verified'), default=
> primary = models.BooleanField(verbose_name=_('primary'), default=True)
> Then you can extend the profile to have (for example):
> @receiver(post_save, sender=User)
> def create_profile(sender, instance, created, **kwargs):
> if created:
> EmailAddress.objects.create(user=instance, verified=False)
> Otherwise the EmailAddress class seems to be unrelated to anything,
> which does not make sense for a relational database.
> On Friday, 11 August 2017 20:32:01 UTC+2, Prithviraj Mitra wrote:
>> I am a fresher in django. I am using django 1.10 with allauth app which
>> takes care of frontend registration, sending user confirmation
>> email,validation, login with email etc. So it all works in the frontend. In
>> the backend I managed to change the user creation form by adding an extra
>> field email.
>> The allauth app inserts 3 rows in 3 tables when a user is created in the
>> 1. auth_user
>> 2. account_emailaddress
>> 3. account_emailconfirmation
>> When adding a user from admin it creates a row in auth_user and
>> general_userprofile(extending django user model) table. I would like to
>> insert a row in account_emailaddress table whenever a user is created via
>> Fields in account_emailaddress are--
>> models.py looks like this --
>> from __future__ import unicode_literals
>> from django.db import models
>> from django.contrib.auth.models import User
>> from django.utils.translation import ugettext as _
>> from django.db.models.signals import post_save
>> from django.dispatch import receiver
>> from ciasroot.util import HashedPk
>> from phonenumber_field.modelfields import PhoneNumberField
>> import math, decimal, datetime, os
>> User._meta.get_field('email').blank = False
>> User._meta.get_field('email')._unique = True
>> class EmailAddress(models.Model):
>> verified = models.BooleanField(verbose_name=_('verified'), default=
>> primary = models.BooleanField(verbose_name=_('primary'), default=True
>> 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,
>> phone_number = PhoneNumberField( blank=True, null=True)
>> @receiver(post_save, sender=User)
>> def create_profile(sender, instance, created, **kwargs):
>> if created:
>> def __str__(self):
>> return self.user.get_full_name()
>> def save(self, *args, **kwargs):
>> super(UserProfile, self).save(*args, **kwargs)
>> How can I fetch userid and email under class EmailAddress and save it to
>> the table.
>> Any help 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 post to this group, send email to email@example.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.