When I am using user.email_confirmed
I am not getting any error but when using user.userprofile.email_confirmed
getting RelatedManager error. Why I am getting this error when trying to get user details from userprofile model?
here is my code:
class UserManagement(AbstractUser):
is_blog_author = models.BooleanField(default=False)
is_editor = models.BooleanField(default=False)
is_subscriber = models.BooleanField(default=False)
is_customer = models.BooleanField(default=False)
email_confirmed = models.BooleanField(default=False) #there is no error when obtaining email_confirmed object from abstract user model.
class UserProfile(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,related_name="userprofile")
email_confirmed = models.BooleanField(default=False)
#I am using this for email verification
class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
six.text_type(user.pk) + six.text_type(timestamp) +
six.text_type(user.userprofile.email_confirmed) #error rising for this line
#six.text_type(user.email_confirmed) #I am not getting error if I use this line
)
account_activation_token = AccountActivationTokenGenerator()
views.py
....others code
if user is not None and account_activation_token.check_token(user, token):
user.userprofile.email_confirmed = True #why it's not working and rising error?
#user.email_confirmed = True #it's working
user.save()
.....others code