在Django中显示UserProfile的注释数
|
如何将UserProfile模型连接到用户的注释?在我的UserProfileAdmin中,我想显示每个用户的评论数。有任何想法吗?
谢谢!
编辑:我的模型:
class UserProfile(models.Model):
GENDER_CHOICES = (
(\'M\', _(\'Male\')),
(\'F\', _(\'Female\')))
user = models.ForeignKey(User, unique=True)
location = models.CharField(max_length=50)
gender = models.CharField(max_length=2, choices=GENDER_CHOICES, blank=True, null=True)
birthdate = models.DateField(blank=True, null=True)
website = models.URLField(blank=True)
description = models.TextField(blank=True)
我还想在查看UserProfile时显示用户的评论列表。由于我使用的是Django的内置注释系统,是否有执行此操作的快捷方式?还是我必须做类似ѭ1的事情?
没有找到相关结果
已邀请:
2 个回复
古擅坛犯
应该这样做。 您可以将其包装到个人档案模型中的方法中
并将“ 4”添加到ModelAdmin中的list_display选项。 如果要获取用户评论的列表,可以相应地调整该方法:
然后,您可以执行以下操作:
要么:
旅牢斯讲
。如果您提供更多代码,我可以更新我的答案(否则其他人会更好)。 更新:对不起,忘记了文档。对于
:http://docs.djangoproject.com/en/dev/ref/models/querysets/#count 过滤器:http://docs.djangoproject.com/en/dev/ref/models/querysets/#filter 用于注册管理员:http://docs.djangoproject.com/en/dev/ref/contrib/admin/