Getting Posts and its last comment in a single queryset

10 views
Skip to first unread message

Hugo Osvaldo Barrera

unread,
Aug 21, 2015, 5:06:43 AM8/21/15
to django...@googlegroups.com
Hi all,

Let's assume I've the classic blog post with multiple comments model.
I'm trying to get a list of posts each annotated with its last comment
(or at least a single field from it).

The closest I've gotten is via:

Post.objects.annotate(last_comment=F('comment__text'))

But this just returns the body for the first commend, and I explicitly
want the last.

Am I missing something pretty obvious? Or is there some smart way of
doing this that I'm failing to see?

Thanks,

--
Hugo Osvaldo Barrera
Reply all
Reply to author
Forward
0 new messages