title: django aggregation to lower resolution using grouping by a date range
body: <p>horrible title, but let me explain: i've got this django model containing a timestamp (date) and the attribute to log - f.e. the number of users consuming some ressource - (value).</p>
  
  <pre><code>class Viewers(models.Model):
      date = models.DateTimeField()
      value = models.IntegerField()
  </code></pre>
  
  <p>for each 10seconds the table contains the number of users. something like this:</p>
  
  <pre><code>| date | value |
  |------|-------|
  |  t1  |   15  |
  |  t2  |   18  |
  |  t3  |   27  |
  |  t4  |   25  |
  |  ..  |   ..  |
  |  t30 |   38  |
  |  t31 |   36  |
  |  ..  |   ..  |
  </code></pre>
  
  <p>now i want to generate different statistics from this data, each with another resolution. f.e. for a chart of the last day i don't need the 10second resolution, so i want 5 minute steps (that are build by averaging the values (and maybe also the date) of the rows from t1 to t29, t30 to t59, ...), so that i'll get:</p>
  
  <pre><code>| date | value |
  |------|-------|
  |  t15 |   21  |
  |  t45 |   32  |
  |  ..  |   ..  |
  </code></pre>
  
  <p>the attributes to keep variable are start &amp; end timestamp and the resolution (like 5 minutes). is there a way using the django orm/queryset api and if not, how to reach this with custom sql?</p>