Django高级注释

Django高级注释,django,python-2.7,django-models,Django,Python 2.7,Django Models,鉴于这种模式: from django.db import models class Post(models.Model): text = models.CharField(max_length=255) class Comment(models.Model): text = models.CharField(max_length=255) needs_attention = models.BooleanField(default=False) creat

鉴于这种模式:

from django.db import models


class Post(models.Model):
    text = models.CharField(max_length=255)


class Comment(models.Model):
    text = models.CharField(max_length=255)
    needs_attention = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    post = models.ForeignKey(Post)
我可以
注释
帖子列表:

Post.objects.annotate(last_comment_date=Max('comment__created_at'))
要了解上次注释日期,请注意如何注释以设置上次注释的值。

尝试以下操作:

needs_attention = Q(comment__needs_attention=True)
Post.objects.annotate(last_comment_date=Max('comment__created_at'), filter=needs_attention)

请再解释一下您的问题。“要设置最后一条注释的值,请注意”是的,我现在想知道
Post
的最后一条注释是否将标记
needs\u attention
设置为
True
。它解释了吗?你可以使用filter Post.objects.filter(need_attention=True)。annotate(last_comment_date=Max('comment_ucreated_at'))对不起,我需要所有的帖子,我想要一个值,它是“last_comment_need_attention”。你所说的可以通过
Post.objects.filter(comment\uu needs\u attention=True)
完成,但这意味着将所有带有
needs\u attention的评论的帖子设置为True。这是完全不同的。您可以使用。