title: django How can I get a weekly average queryset
body: <p>I have two models that are linked.  Here is a subset for simplicity:</p>
  
  <pre><code>class Job(models.Model):
      event = models.OneToOneField(Event, on_delete=models.CASCADE, null=False, blank=False)
      completion_time = models.DateTimeField(db_index=True, null=True, blank=True)
      labor_price = models.FloatField(verbose_name='Final Labor Price', blank=True, null=True)
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>class Event(models.Model):
      start_time = models.DateTimeField(db_index=True, null=True, blank=True)
      end_time = models.DateTimeField(db_index=True, null=True, blank=True)
  </code></pre>
  
  <p>I need to get a few things, and I know they can be done in SQL, but I'm not sure how to do them in django.  I need monthly and weekly averages for the <code>labor_price</code> of jobs.  In other words, something like this, and I may have it wrong for what I'm doing, as I haven't tested it:</p>
  
  <pre><code>SELECT `schedule_event.start_time`, AVG(`jobs_job.labor_price`)
  FROM jobs_job
  INNER JOIN schedule_event on jobs_job.event_id = schedule_event.id
  GROUP BY YEAR(`schedule_event.start_time`), MONTH(`schedule_event.start_time`)
  HAVING COUNT(`schedule_event.start_time`) = DAY(LAST_DAY(`schedule_event.start_time`));
  </code></pre>
  
  <p>I also need to get the average hourly labor price for the week, but I'm not quite sure how that would work at the moment.  It would be a query that would do something like  <code>average(labor_price/(completion_time - event__start_time))</code> on a given filter of dates.</p>