title: Django: Group by date (day, month, year)
body: <p>I've got a simple Model like this:</p>
  
  <pre><code>class Order(models.Model):
      created = model.DateTimeField(auto_now_add=True)
      total = models.IntegerField() # monetary value
  </code></pre>
  
  <p>And I want to output a month-by-month breakdown of:</p>
  
  <ul>
  <li>How many sales there were in a month (<code>COUNT</code>)</li>
  <li>The combined value (<code>SUM</code>)</li>
  </ul>
  
  <p>I'm not sure what the best way to attack this is. I've seen some fairly scary-looking extra-select queries but my simple mind is telling me I might be better off just iterating numbers, starting from an arbitrary start year/month and counting up until I reach the current month, throwing out simple queries filtering for that month. More database work - less developer stress!</p>
  
  <p>What makes most sense to you? Is there a nice way I can pull back a quick table of data? Or is my dirty method probably the best idea?</p>
  
  <p>I'm using Django 1.3. Not sure if they've added a nicer way to <code>GROUP_BY</code> recently.</p>