【发布时间】:2015-06-13 17:09:50
【问题描述】:
如何获取用户的用户资料?
我有自己的 cmets 应用程序
型号:
APPS = (
(1, 'Game'),
(2, 'Article'),
(3, 'CMS'),
(4, 'User profile'),
)
comment_type = models.IntegerField(choices=APPS,
default=1,
verbose_name="Comment Type")
object_id = models.IntegerField(default=0)
user = models.ForeignKey(User, null = True, blank = False, related_name='user')
查看:
context = {
...
'comments': Comment.objects.filter(comment_type=1, object_id=game_id),
...
}
用户资料:
class UserProfile(models.Model):
user = models.OneToOneField(User)
signature = models.TextField(blank=True)
我的看法:
{% for comment in comments %}
....
{{ comment.user.profile.signature }}
{% endfor %}
我是 django 菜鸟。谢谢。
【问题讨论】: