0

Have a UserProfile object that successfully extends the django default user class:

class UserProfile(models.Model):

    user = models.OneToOneField(User)

and have updated the settings.py file accordingly:

AUTH_PROFILE_MODULE = 'authorization.UserProfile'

Everything works fine, just wondering: how do I get to objects associated with UserProfile for a given context within a view?

Assume that I can just get context.user if the user is logged in, but then how do I grab the corresponding UserProfile object?

4

2 回答 2

2

鉴于:

 request.user.get_profile().field_name

在模板中:

 {{user.userprofile.field_name}}
于 2013-02-15T07:46:55.030 回答
0

你可以得到它 -

context.user.userprofile

详细在这里

于 2013-02-15T07:44:46.333 回答