Let's say I have two models looking like this:
class ProductType(models.Model): product_type = models.CharField(max_length=100) class Product(models.Model): name = models.CharField(max_length=200) slug = models.SlugField() product_type = models.ForeignKey(ProductType) score = models.PositiveIntegerField(default=0)
Now I want to fetch the top two products (the two with highest score) from each ProductType. So if I have Phones, Computers, TVs as ProductTypes I want the two best Phones, Computers, TVs.
As I don't even know how to do this in MySQL I've tried searching for the MySQL-solution but the ones I find is extremely complex and this doesn't feel like an extremely complex thing to do.
I am leaning towards making an own model for the top products and have a cronjob to fix this, but I'd like to see if there's an easier solution to this.