title: How to filter a nested serializer's field in Django DRF
body: <p>I have two models named 'School' and 'Student'. I've created each's serializers and the nested serializer for School having a student serializer as a nested field. </p>
  
  <p>Here I want to apply filters on the fields of the serializers using 'django-filters' and it is almost working, BUT ...the problem is that when I filter the nested field, i-e 'students's field' , It doesn't show me the required result.
  My models are :</p>
  
  <pre><code>class School(models.Model):
      name = models.CharField(max_length=256)
      principal = models.CharField(max_length=256)
      location = models.CharField(max_length=256)
      is_government = models.BooleanField(default=True)
  
      def __str__(self):
          return self.name
  
  
  class Student(models.Model):
      name = models.CharField(max_length=256)
      age = models.PositiveIntegerField()
      school = models.ForeignKey(School,related_name='students',on_delete = models.CASCADE)
      is_adult  = models.BooleanField(default=True)
  
      def __str__(self):
          return self.name
  </code></pre>
  
  <p>and my serializers are:</p>
  
  <pre><code>class SchoolSerializer(serializers.ModelSerializer):
  
      def __init__(self, *args, **kwargs):
      # Don't pass the 'fields' arg up to the superclass
          # Instantiate the superclass normally
          super(SchoolSerializer, self).__init__(*args, **kwargs)
          allow_students = self.context.get("allow_students",None)
          if allow_students:
              self.fields['students'] = StudentSerializer(many=True, context=kwargs['context'], fields=['name','age','is_adult']) 
  
  
      class Meta():
          model = School
          fields = '__all__'
  
  
  class StudentSerializer(DynamicFieldsModelSerializer):
      class Meta():
          model = Student
          fields = '__all__'
  </code></pre>
  
  <p>and these are the filters that i am using in my views:</p>
  
  <pre><code>from django_filters.rest_framework import DjangoFilterBackend
  from django_filters import FilterSet
  from django_filters import rest_framework as filters
  
  
  class SchoolStudentAPIView(generics.ListAPIView, mixins.CreateModelMixin):
      queryset              = School.objects.all()
      serializer_class      = SchoolSerializer
  
      filter_backends       = (DjangoFilterBackend,)
      filter_fields         = ('is_government','students__is_adult')
  </code></pre>
  
  <p>Here, the issue is that when i search for "students__is_adult", which is a nested field, It filters out the list of students that are adult ALONG WITH THE students that are not. </p>
  
  <p>Can someone add something extra or give another solutuion? thank you</p>