Search code examples
djangodjango-users

is there a difference between request.user and actual User object?


I have defined my UserDetail model, which has one to one relation with User.

class UserDetail(models.Model):
    user = models.OneToOneField(User)
    ....

but when I am trying to access UserDetail object through request.user in my view it is throwing me error as "User has no userdetail.".

form = UpdateProfile(request.user.userdetail)

while I am able to use user.userdetail in Django shell. I have no idea why it is happening, is request.user have some differences with User object?


Solution

  • No. It is because that particular user does not have an associated UserDetail instance.