I've posted this issue on Stackoverflow
Given this model:
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)
I can annotate
the list of posts with:
Post.objects.annotate(last_comment_date=Max('comment__created_at'))
to know the last_comment_date
, how to annotate to set a value for last_comment_needs_attention
?
How can obtain details from the last comment when listing ll posts?
Thanks!