开发者

How do I get django comments to join on auth_user

I'm using the django comments framework, and when I list the comments I want to include some of the information stored in auth_user. However, I find I need an extra query for each comment to get the user info.

I tried using select_related() when I pull the comments, but this doesn't help.

Is there a reason that it's not joining the auth_user table, and is there any wa开发者_运维问答y to force it to?


here is a snip from the original django comments model:

    user        = models.ForeignKey(User, verbose_name=_('user'),
                    blank=True, null=True, related_name="%(class)s_comments")
    user_name   = models.CharField(_("user's name"), max_length=50, blank=True)
    user_email  = models.EmailField(_("user's email address"), blank=True)
    user_url    = models.URLField(_("user's URL"), blank=True)

so you can use comment.user to get your user and/or user.users_comments to get all comments of your user:-)


You could get all of the users that have comments on your page then dump them into a dictionary. The you can pull user data from your dictionary while looping over the comments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜