title: How to group by values based on common elements of the queryset in Django view?
body: <p>I'm new to Django and I need this data to render some chart please help
  I must get my queryset as a dictionary in a specific structure</p>
  
  <p>This is my view:</p>
  
  <pre><code>def pr1(request):
      fdate = unidecode(str(request.GET.get('fdate')))
      tdate = unidecode(str(request.GET.get('tdate')))                
  
      dataSource = OrderedDict()
      dataSource["dataset"] = []
  
      for key in Production.objects.filter(date__range=(fdate, tdate)).values('date', 'comName').annotate(total_qty=Sum('qty')):
  
          seriesname = {}
          data = {}        
          data["seriesname"]     = key['comName']
          data["value"]          = key['total_qty']
          dataSource["dataset"].append(data) 
  </code></pre>
  
  <p>This is output of my query:</p>
  
  <pre><code>[
   {'date': '1398/08/01', 'comName': 'a', 'total_qty': 253.0}, 
   {'date': '1398/08/02', 'comName': 'a', 'total_qty': 263.0}, 
   {'date': '1398/08/01', 'comName': 'b', 'total_qty': 3.938}, 
   {'date': '1398/08/02', 'comName': 'b', 'total_qty': 31.625}
  ]
  </code></pre>
  
  <p>datasource after appending:</p>
  
  <pre><code>"dataset": [
    {
      "seriesname": "a",
      "value": 253
    },
    {
      "seriesname": "a",
      "value": 263
    },
    {
      "seriesname": "b",
      "value": 3.938
    },
    {
      "seriesname": "b",
      "value": 31.625
    }
  </code></pre>
  
  <p>but I have to get it as following:</p>
  
  <pre><code>"dataset": [
  {
      "seriesname": "a",
      "data": [
          {
              "value": "253"
          },
          {
              "value": "263"
          }]},
          {
      "seriesname": "b",
      "data": [
          {
              "value": "3.938"
          },
          {
              "value": "31.625"
          }]}
          ]
  </code></pre>