title: django rest framework- how can I pass query params to foreign key serializer?
body: <p>For my application, I have Locations, and Events given by the following (simplified) models:</p>
  
  <pre><code>class Location(models.Model):
      name = models.CharField(max_length=64)
  
  class Event(models.Model):
      location = models.ForeignKey(Location)
      date = models.DateField()
  </code></pre>
  
  <p>In my API, I have an endpoint: <code>/api/locations/</code> which returns all locations, and each location has its events embedded within it, e.g.:</p>
  
  <pre><code>[
      {
          'id': 1,
          'name': 'Location 1',
          'events': [
              {'id': 1, 'date': '2018-01-01'},
              {'id': 2, 'date': '2018-01-14'}
          ]
       },
       {
          'id': 2,
          'name': 'Location 2',
          'events': [
              {'id': 3, 'date': '2017-12-28'},
              {'id': 4, 'date': '2018-01-10'}
          ]
       }
  ]
  </code></pre>
  
  <p>my serializers look like:</p>
  
  <pre><code>class EventSerializer(serializers.ModelSerializer):
      class Meta:
          model = Event
          fields = ('id', 'date',)
          read_only_fields = ('id',)
  
  class LocationSerializer(serializers.ModelSerializer):
      events = EventSerializer(many=True)
      class Meta:
          model = Location
          fields = ('id', 'name', 'events',)
          read_only_fields = ('id',)
  </code></pre>
  
  <p>Using ViewSets, I would like to add a filter to this call, with a <code>max_date</code>, and <code>min_date</code> parameter, e.g.: <code>/api/locations/?min_date=2018-01-01&amp;max_date=2018-01-15</code>.  Which should return only locations that have events between those two dates, AND should only return the events for each location between those two dates.</p>
  
  <p>In the example data above, both locations would return, Location 1 would have both events listed, but Location 2 would only have the second event in its list.  In my ViewSet, I can take those parameters and append them as queryset filters:</p>
  
  <pre><code>class LocationViewSet(mixins.RetrieveModelMixin,
                        mixins.ListModelMixin,
                        viewsets.GenericViewSet):
      serializer_class = LocationSerializer
  
      def get_queryset(self):
          queryset = Location.objects.all()
          min_date = self.request.query_params.get('min_date', None)
          max_date = self.request.query_params.get('max_date', None)
          if min_date is not None and max_date is not None:
              queryset = queryset.filter(event__date__lte=max_date, event__date__gte=min_date)
          return queryset
  </code></pre>
  
  <p>Which will filter out any locations that do not have any events between the two dates, however those returned locations show ALL of their events, not just the ones between <code>min_date</code> and <code>max_date</code>.  I assume I have to somehow pass my query parameters on to the <code>EventSerializer</code> embedded within <code>LocationSerializer</code>, but am unsure as to how I might do this.</p>