class Post(models.Model):
title = ...
category = models.ForeignKey(Category)
date = .......
class Category(models.Model):
title = ....
On the main page i want to display 5 posts with latest dates, but all posts must be from different categories. There is 50 categoriese, for example. Is it possible?
That annotates the categories with the date of the most recent post as the value of
most_recent, which you can then order by to get the 5 most recent categories.Then, just loop through the categories and pull out the latest post for each. Done.