Post has user and date attributes.
How can I turn this
posts = Post.objects.order_by('-date')[:30]
to give me 30 or less posts consisting of the last post by every user?
For example if I have 4 posts stored, 3 are from post.user=”Benny” and 1 from post.user=”Catherine” it should return 1 post from Benny and 1 from Catherine ordered by date.
I would probably use
annotate, you might be able to useextrato get down to a single query.You could also use
raw, which would let you write a SQL query, but still return model instances. For instance: