title: Dynamically adding field in Django Rest Framework generics.ListAPIView
body: <p>I have a view that can be called with a <code>longitude</code> and <code>latitude</code> parameters.</p>
  
  <p>When those parameters are set, I want the response to add the distance fields in the serialization.</p>
  
  <p>Here is how I do that:</p>
  
  <pre><code>def get_queryset(self):
      latitude = self.request.QUERY_PARAMS.get('latitude', None)
      longitude = self.request.QUERY_PARAMS.get('longitude', None)
      if latitude and longitude:
          center = fromstr('POINT(%s %s)'%(latitude,longitude))
          queryset = queryset.distance(center).order_by('distance')
          self.serializer_class.distance = serializers.CharField(source='distance')
          self.serializer_class.Meta.fields += ('distance',)
      return queryset.all()
  </code></pre>
  
  <p>I think I could have done if differently, with two separate <code>serializer_class</code>.</p>
  
  <p>I am wondering if it would have been better, what do you think?</p>