[Answer]-How can I write a Django query to aggregate the most recently published entry for each author of a collective blog?

1👍

Found the answer here:

Django query that get most recent objects from different categories

authors = Author.objects.annotate(latest_entry_published_on=Max('entries__published_on')) 
entries = Entry.objects.filter(published_on__in=[a.latest_entry_published_on for a in authors])

0👍

I’d try something like:

Entry.objects.order_by('-published_on').values_list('author_id').distinct()

Leave a comment