title: Django: Query Group By Month
body: <p>How to calculate total by month without using extra?</p>
  
  <p>I'm currently using:</p>
  
  <ul>
  <li>django 1.8</li>
  <li>postgre 9.3.13</li>
  <li>Python 2.7</li>
  </ul>
  
  <p>Example.</p>
  
  <p><a href="https://i.stack.imgur.com/aZ1Fm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aZ1Fm.png" alt="enter image description here"></a></p>
  
  <p><strong>What I have tried so far.</strong></p>
  
  <pre><code>#Doesn't work for me but I don't mind because I don't want to use extra
  truncate_month = connection.ops.date_trunc_sql('month','day')
  invoices = Invoice.objects.filter(is_deleted = False,company = company).extra({'month': truncate_month}).values('month').annotate(Sum('total'))
  
  ----
  #It works but I think that it's too slow if I query a big set of data
  for current_month in range(1,13):
      Invoice.objects.filter(date__month = current__month).annotate(total = Sum("total"))
  </code></pre>
  
  <p>and also this one, the answer seems great but I can't import the TruncMonth module.</p>
  
  <p><a href="https://stackoverflow.com/questions/8746014/django-group-by-date-day-month-year">Django: Group by date (day, month, year)</a></p>
  
  <hr>
  
  <p>P.S. I know that this question is already asked multiple times but I don't see any answer.</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p><strong>SOLUTION</strong>:</p>
  
  <p>Thanks to @Vin-G's answer.</p>
  
  <p><a href="https://i.stack.imgur.com/ZV8e3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZV8e3.png" alt="enter image description here"></a></p>