module object has no attribute after using different version of Python
I have both versions python 2.7 and 3.4 installed. I am using some code which is developed under 2.7 but I am using under 3.4. So after compiling using the following command python manage.py runserver I get the following error - File "C:\pyprojects\focus\site\general\forms.py", line 26, in Meta model = models.UserProfile AttributeError: 'module' object has no attribute 'UserProfile' As models.py and forms.py is under same directory(general) so I have imported the model in forms.py in this way from .models import models Now in models.py I have defined the class class UserProfile(models.Model, HashedPk): user = models.OneToOneField(User, unique=True) is_pro = models.BooleanField(default=False, blank=True) .. In forms.py the code is class UserProfileForm(forms.ModelForm): class Meta: model = models.UserProfile . Is there any special way to call the model in python 3.4. 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 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/45963943-9580-44a0-b823-50b5b393f496%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to insert a row in another table once a user is created
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 frontend. 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 admin. Fields in account_emailaddress are-- id email verified primary user_id 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=True) primary = models.BooleanField(verbose_name=_('primary'), default=True) 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) 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 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/1e1057af-4abe-4f0c-aecf-a31cdc729bc8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to insert a row in another table once a user is created
Hi Derek, Many thanks for your suggestion. I made some progress since I posted this topic. The new row has been created in EmailAddress table but the email is blank. I can't find a solid reason. In the admin user creation form there is an email field and the table auth_user has got the email. So why the EmailAddress model is not getting the email value. As the admin is creating the user so no verification is needed. So field verified is true. Updated code from models.py class EmailAddress(models.Model, HashedPk): 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) In userprofile model there is no email though. Is there any way I can pass email to the EmailAddress model. 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= > True) > 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: > UserProfile.objects.create(user=instance) > 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 >> frontend. >> >> 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 >> admin. >> >> Fields in account_emailaddress are-- >> >> id >> email >> verified >> primary >> user_id >> >> 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= >> True) >> primary = models.BooleanField(verbose_name=_('primary'), default=True >> ) >> >> >> 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) >> organisatio
Re: How to insert a row in another table once a user is created
I have got some updates. Basically what I want is if admin creates a user then no verification is needed. He/she can straight go to the login page and login with the email and password which was emailed to the user.(I need to do this email part later though) Now another issue has raised with this line -- EmailAddress.objects.create(user=instance, verified=False) When the user tries to signup from the frontend then there is a error -- assert not EmailAddress.objects.filter(user=user).exists() AssertionError Because my code has already created a row in EmailAddress table and django-allauth app is trying to insert the same row again. May be that's why? rday, 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= > True) > 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: > UserProfile.objects.create(user=instance) > 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 >> frontend. >> >> 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 >> admin. >> >> Fields in account_emailaddress are-- >> >> id >> email >> verified >> primary >> user_id >> >> 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= >> True) >> primary = models.BooleanField(verbose_name=_('primary'), default=True >> ) >> >> >> 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) >> >> >> >> >> 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 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/6cac720f-8c4e-4592-87b6-28f0dd7e5a30%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to insert a row in another table once a user is created
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= > True) > 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: > UserProfile.objects.create(user=instance) > 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 >> frontend. >> >> 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 >> admin. >> >> Fields in account_emailaddress are-- >> >> id >> email >> verified >> primary >> user_id >> >> 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= >> True) >> primary = models.BooleanField(verbose_name=_('primary'), default=True >> ) >> >> >> 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) >> >> >> >> >> 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 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/a0cbe6db-653a-4641-8db4-ff96141c2f74%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Assertionerror because of custom user model and django allauth
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.
Only admin can create an object from a model
I want the admin only to create a object from a model. Is it possible? #EmailAddress.objects.create(user=instance, email=instance.email) >From models.py 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' @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) 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 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/30e452a0-d6cd-48c5-932a-96b13ca68601%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.