title: Equivalent Django query using filter, annotate and value
body: <pre><code>mysql&gt; select final_category, sum(base) as base, sum(responders) as responders from Johnson_jnjusage
  where (bucket="key influencer") and (category1="strong influence") and
  (child_age_group = "0 to 12 months") and (sec = "A1") and (no_of_people_house="3")
  and (nursing_cnt="1ST TIME MOTHER") and
  (city="DELHI" or CITY="HYDERABAD") group by final_category;
  </code></pre>
  
  <p>I want to write equivalent query in django. Right now I'm doing something like this in my views.py</p>
  
  <pre><code>kwargs1 = {}
  
  if age != None:
      kwargs1['child_age_group__in'] = json.loads(age) #age is the json object converted to list which can have multiple values
  
  if sec != None:
      kwargs1['sec__in'] = json.loads(sec)
  if reg != None:
      kwargs1['no_of_people_house__in'] = json.loads(reg)
  
  if nurse != None:
      kwargs1['nursing_cnt__in'] = json.loads(nurse)
  if city != None:
      kwargs1['city__in'] = json.loads(city)
  
  if bucket != '' and bucket != None:
      kwargs1['bucket'] = bucket
  
  if category1 != '' and category2 != None:
      kwargs1['category1']  = category1
  
  if category2 != '' and category2 != None:
      kwargs1['category2'] = category2 
  </code></pre>
  
  <p>and the query which I'm doing write now is </p>
  
  <pre><code>finalCatBaseResponders = JnJUsage.objects.filter( **kwargs1).values('final_category').annotate(base=Sum('base'), responders = Sum('responders'))
  </code></pre>
  
  <p>but I'm not getting similar results, If anyone could help me, I have wasted 3 days but I can not get it rightly done. I want to get similar result which is mentioned down from Django query.</p>
  
  <p>Results from MySQL query is </p>
  
  <pre><code>+----------------------------------------+------+------------+
  | final_category                         | base | responders |
  +----------------------------------------+------+------------+
  |   Friends/acquaintances                |    3 |          0 |
  |  Advertising                           |    3 |          1 |
  |  Baby care stores                      |    3 |          0 |
  |  Baby Club                             |    3 |          0 |
  |  Baby-care experts                     |    3 |          0 |
  |  Babysitter / Nanny / Daycare Provider |    3 |          0 |
  |  By my own experience                  |    3 |          1 |
  |  Father                                |    3 |          1 |
  |  Friends                               |    3 |          0 |
  |  General health workers                |    3 |          0 |
  |  General medical practitioners/doctors |    3 |          0 |
  |  Husband                               |    3 |          1 |
  |  Internet search                       |    3 |          0 |
  |  Malish Wali                           |    3 |          0 |
  |  Midwives                              |    3 |          0 |
  |  Mother                                |    3 |          1 |
  |  Mother-in-law                         |    3 |          1 |
  |  Newspaper                             |    3 |          0 |
  |  Nurses                                |    3 |          0 |
  |  Obstetrician-Gynecologist             |    3 |          0 |
  |  Online forum                          |    3 |          0 |
  |  Other Relatives                       |    3 |          0 |
  |  Pediatricians                         |    3 |          1 |
  |  Senior Mothers                        |    3 |          0 |
  |  Sisters/sisters-in-law                |    3 |          0 |
  |  Specialist baby information sites     |    3 |          0 |
  |  Website from brands                   |    3 |          0 |
  +----------------------------------------+------+------------+
  </code></pre>
  
  <p>Thanks</p>