Django检索用户的所有注释

Django检索用户的所有注释,django,django-comments,profiles,django-profiles,Django,Django Comments,Profiles,Django Profiles,我正在使用django配置文件和django.contrib.comments,并试图在其配置文件中显示特定用户的所有注释 这是使用django profiles中的默认profile_详细视图 我尝试过这两种方法,虽然与此查询匹配的对象确实存在,但都没有返回任何对象: {% for comment in profile.user.comment_set.all %} 及 在django.contrib.comments的源代码中,注释模型中用户的外键具有以下相关名称: user = mode

我正在使用django配置文件和django.contrib.comments,并试图在其配置文件中显示特定用户的所有注释

这是使用django profiles中的默认profile_详细视图

我尝试过这两种方法,虽然与此查询匹配的对象确实存在,但都没有返回任何对象:

{% for comment in profile.user.comment_set.all %}

在django.contrib.comments的源代码中,注释模型中用户的外键具有以下相关名称:

user = models.ForeignKey(User, verbose_name=_('user'),
                    blank=True, null=True, related_name="%(class)s_comments")
注释还有一个自定义管理器:

# Manager
    objects = CommentManager()
定义为:

class CommentManager(models.Manager):

    def in_moderation(self):
        """
        QuerySet for all comments currently in the moderation queue.
            """
        return self.get_query_set().filter(is_public=False, is_removed=False)

    def for_model(self, model):
        """
        QuerySet for all comments for a particular model (either an instance or
        a class).
        """
        ct = ContentType.objects.get_for_model(model)
        qs = self.get_query_set().filter(content_type=ct)
        if isinstance(model, models.Model):
            qs = qs.filter(object_pk=force_unicode(model._get_pk_val()))
        return qs

自定义管理器是否导致.all查询不返回任何内容?我是否正确访问反向关系?任何帮助都将不胜感激。

相关名称已定义,因此默认名称集将无法使用。相关的_名称的目的是覆盖默认的反向管理器名称

 user = models.ForeignKey(User, verbose_name=_('user'),
                blank=True, null=True, related_name="%(class)s_comments")
所以用这个:

user.comment_comments.all()

谢谢我使用了错误的类名user而不是comment。实际上应该是:user.comment\u comments.all。应切换末端的s。
user.comment_comments.all()