0

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?

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
vivek
  • 5
  • 1

1 Answers1

3

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

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 1
    or there is not logged in user, so you are actually looking at `django.contrib.auth.models.AnonymousUser` – Burhan Khalid Jul 13 '15 at 12:03
  • Thanks a lot @daniel , I was thinking that current user have UserDetail instance for him but unfortunately I was logged in as super user which doesn't. – vivek Jul 13 '15 at 12:15
  • thanks @burhan for editing my question and pointing out another scenario. – vivek Jul 13 '15 at 12:17