vivek
vivek

Reputation: 5

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?

Upvotes: 0

Views: 207

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599778

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

Upvotes: 3

Related Questions