title: Django aggregation: Sales by Category
body: <p>i'm trying to get a total of sales by category.</p>
  
  <p>I know there is a way to do this with python, but i would rather do it with querys or aggregation.</p>
  
  <p>My models:</p>
  
  <pre><code>class Item(models.Model):
     category= models.ForeignKey(Category)
     name = models.CharField(max_length=40)
  
  class Category(models.Model):
     name = models.CharField(max_length=40)
  
  class Store(models.Model):
     name=models.CharField(max_length=40)
  
  class Sale(models.Model):
     item=models.ForeignKey(Item)
     store=models.ForeignKey(Store)
     quantity=models.IntegerField()
  
  class Store_Item(models.Model):
     item=models.ForeignKey(Item)
     store=models.ForeignKey(Store)
     price= models.DecimalField(max_digits=10, decimal_places=2)
  </code></pre>
  
  <p>The result should be something like this:</p>
  
  <pre><code>          sales total
  books     100   859.10
  audio     200   1894.20
  
  total     300   2753.3    
  </code></pre>
  
  <p>Right now i'm getting the total quantity of every category like this:</p>
  
  <pre><code>p=Sale.objects.all().values('item__category__name').order_by('item__category__name').annotate(total=Sum('quantity'))
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>books  100
  audio  200
  </code></pre>
  
  <p>But i'm stuck in the prices part.</p>
  
  <p>Any help would be greatly appreciated.
  Thanks in advance!</p>