SUDAPP SUDAPP - 3 years ago 387
Python Question

confirmation Email and how to access and alter user's profile fields?

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.

class Profile(models.Model):
# relations
user = models.OneToOneField(User, on_delete=models.CASCADE)
email_confirmed = models.BooleanField(default=False)

class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
six.text_type( + six.text_type(timestamp) +

account_activation_token = AccountActivationTokenGenerator()

views.activate, name='activate'),

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
login(request, user)
return redirect('home')
return render(request, 'account_activation_invalid.html')

Answer Source

Try inserting

before your


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download