title: aggregate or annotate with condtion in django
body: <p>I am new to django and SQL queries. I am trying some annotation with distinct in django. but unable to get results. My table looks like</p>
  
  <pre><code>+-----------------------+-----------+---------------------+
  | email                 | event     | event_date          |
  |-----------------------+-----------+---------------------|
  | hector@example.com    | open      | 2017-01-03 13:26:13 |
  | hector@example.com    | delivered | 2017-01-03 13:26:28 |
  | hector@example.com    | open      | 2017-01-03 13:26:33 |
  | hector@example.com    | open      | 2017-01-03 13:26:33 |
  | tornedo@example.com   | open      | 2017-01-03 13:34:53 |
  | tornedo@example.com   | click     | 2017-01-03 13:35:22 |
  | tornedo@example.com   | open      | 2016-09-05 00:00:00 |
  | tornedo@example.com   | open      | 2016-09-17 00:00:00 |
  | sparrow@example.com   | open      | 2017-01-03 16:05:36 |
  | tornedo@example.com   | open      | 2017-01-03 20:12:15 |
  | hector@example.com    | open      | 2017-01-03 22:06:47 |
  | sparrow@example.com   | click     | 2017-01-09 19:46:26 |
  | sparrow@example.com   | open      | 2017-01-09 19:47:59 |
  | sparrow@example.com   | open      | 2017-01-09 19:48:28 |
  | sparrow@example.com   | delivered | 2017-01-09 19:52:24 |
  +-----------------------+-----------+---------------------+
  </code></pre>
  
  <p>Model is like:</p>
  
  <pre><code>class EmailEvent(models.Model):
      event = models.TextField(blank=True, null=True)
      email = models.TextField(blank=True, null=True)
      event_date = models.DateTimeField(blank=True, null=True)
  </code></pre>
  
  <p>I want distinct count for different event column values. For example
  <code>EmailEvent.objects.filter(event='open').distinct('email').count()</code> results 3
  <code>EmailEvent.objects.filter(event='click').distinct('email').count()</code> results 2
  <code>EmailEvent.objects.filter(event='delivered').distinct('email').count()</code> results 2</p>
  
  <p>how to get result with aggregate or annotate in one query ? I want results like</p>
  
  <pre><code>{
  'open': 3,
  'click': 2,
  'delivered': 2,
  } 
  </code></pre>
  
  <p>Thanks !</p>