title: How could create a crosstab SQL query with Django ORM?
body: <p>Using Django 1.1, how could I create a crosstab (pivot table) SQL query using the ORM?</p>
  
  <p>UPDATED:
  These are the models and output requirements:</p>
  
  <pre><code>class Store(models.Model):
      name = models.CharField(max_length=255)
      ...
  
  class Order(models.Model):
      store = models.ForeignKey(Store, blank=True, null=True, related_name='orders')
      description = models.CharField(_('Description'), max_length=255)
      quantity = models.IntegerField(blank=True, null=True)       
      type_detail = models.CharField(_('Type Detail'), max_length=255)
      slug = models.SlugField(blank=True)
      cost = models.DecimalField(_("Cost"), max_digits=14, decimal_places=2)
      modified = models.DateTimeField(_('modified'), auto_now=True)
  </code></pre>
  
  <p>Currently the view is showing data like so:</p>
  
  <pre><code>Store   | Type Detail  | Quantity 
  ----------------------------------
  Walmart | Floor polish | 2        
  Walmart | Tiles        | 1        
  Walmart | Milk         | 4      
  Another | Floor polish | 2        
  Another | Tiles        | 1        
  Another | Milk         | 4        
  </code></pre>
  
  <p>I want to pivot this to view the data like so:</p>
  
  <p>For a store I need to know quantities</p>
  
  <pre><code>Store   | Floor polish  | Tiles | Milk
  ------------------------------------------------
  Walmart | 2             | 1     | 4
  Another | 2             | 1     | 4
  </code></pre>
  
  <p>I hope that explains what I need.</p>