I am following a tutorial and everything is working fine, except being able to access the user's profile fields , and so far i am able to set the 'is_active' flag on User model, put 'user.profile.email_confirmed' is really not changing at all,so any Idea about what is that i am doing wrong.
user = models.OneToOneField(User, on_delete=models.CASCADE)
email_confirmed = models.BooleanField(default=False)
def _make_hash_value(self, user, timestamp):
six.text_type(user.pk) + six.text_type(timestamp) +
account_activation_token = AccountActivationTokenGenerator()
def activate(request, uidb64, token):
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
except (TypeError, ValueError, OverflowError, User.DoesNotExist):
user = None
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
user.profile.email_confirmed = True
return render(request, 'account_activation_invalid.html')
It may help to view things from the underlying DBs perspective. Usually relations are stored as integers representing foreign keys to an entry in another database table.
Thus when you execute
you are writing to the DB that
is_active is now set to True but the user profile is still the same integer value as before, as you didn't change the profile object that the user has. As far as I know, Django doesn't go out of its way to figure out that the profile object has also been changed.