I have the following models:
class Website(models.Model):
name = models.CharField(max_length=256, unique=True)
class Product(models.Model):
website = models.ForeignKey('Website')
name = models.CharField(max_length=512)
I'd like to run a query to get a list of lists of products grouped by their websites name.
An example:
Website 1 : name: 'ebay' Website 2: name: 'amazon'
Product 1 : name: 'pc' website: 'ebay' Product 2 : name: 'notebook' website: 'amazon' Product 3 : name: 'smartphone' website: 'amazon'
I'd like to get something like: [[Product1], [Product2, Product3]]
I've been looking here and in the django docs but I couldn't find a proper way to do it.