title: Django : KeyError: "Got KeyError when attempting to get a value for field `channel` on serializer ``
body: <p>model</p>
  <pre class="lang-py prettyprint-override"><code>
  class Metric(models.Model):
  
      date = models.DateField()
      channel = models.CharField(max_length=50)
      country = models.CharField(max_length=10)
      os = models.CharField(max_length=10)
      impressions = models.IntegerField()
      clicks = models.IntegerField()    
  
      def __str__(self):
          return &quot;{} - {}&quot;.format(self.date, self.channel)
  </code></pre>
  <p>My view</p>
  <pre class="lang-py prettyprint-override"><code>class MetricViewSet(viewsets.ModelViewSet):
  
      serializer_class = MetricSerializer
      queryset = Metric.objects.all()
      filter_backends = [DjangoFilterBackend]
      filterset_class = MetricFilter
  </code></pre>
  <p>My serializer</p>
  <pre class="lang-py prettyprint-override"><code>class MetricSerializer(serializers.ModelSerializer):
      class Meta:
          model = Metric
          fields = '__all__'
  </code></pre>
  <p><strong>I need to group by one or more columns: date, channel, country, operating system</strong> and serialize it. Can someone help me with how I can do it?</p>
  <pre><code>select channel, country, sum(impressions) as impressions, sum(clicks) as clicks from sample dataset where date &lt; '2017-06-01' group by channel, country order by clicks desc;
       channel      | country | impressions | clicks 
  ------------------+---------+-------------+--------
   adcolony         | US      |      532608 |  13089
   apple_search_ads | US      |      369993 |  11457
   vungle           | GB      |      266470 |   9430
   vungle           | US      |      266976 |   7937
  </code></pre>
  <p>My view</p>
  <pre class="lang-py prettyprint-override"><code>lass MetricViewSet(viewsets.ModelViewSet):
  
      serializer_class = MetricSerializer
      queryset = Metric.objects.all()
      filter_backends = [DjangoFilterBackend]
      filterset_class = MetricFilter
  
      def get_queryset(self):
          sort_by_dict = {'asc': '', 'desc': '-'}
          queryset = Metric.objects.all()        
          group_by = self.request.query_params.get('group_by', None)
          # grouping the queryset
          if group_by is not None:
              queryset = queryset.values(group_by).annotate(dcount=Count(group_by))#.order_by()               
  
          return queryset
  </code></pre>
  <p>I am getting the following error</p>
  <pre><code>KeyError: &quot;Got KeyError when attempting to get a value for field `channel` on serializer `MetricSerializer`.\nThe serializer field might be named incorrectly and not match any attribute or key on the `dict` instance.\nOriginal exception text was: 'channel'.&quot;
  </code></pre>