title: How to overwrite get method in generic RetrieveAPIView in django rest framework to filter the results
body: <p>I have an API that can list several buildings. Each building belongs to several building groups and each building group contains several buildings. </p>
  
  <p>I want to show single fields of one building group. More specifically I want to show all buildings of one building group in my RetrieveAPIView. </p>
  
  <p>I can list a single BuildingGroup instance using the generic view like so: </p>
  
  <pre><code>class BuildingGroupRetrieveAPIView(RetrieveAPIView):
      serializer_class = BuildingGroupSerializer
      queryset = BuildingGroup.buildings.all()
  
  </code></pre>
  
  <p>I assume that I can overwrite the get method to only display a single field of that retrieved object. Specifically I want to display all the objects that are in my many to many relation. Or better to say, I want to retrieve all the complete data within my m2m relation. </p>
  
  <p>Here are my models: </p>
  
  <pre><code>class Building(models.Model):
      name  = models.CharField(max_length=120, null=True, blank=True)
  
      def __str__(self):
          return self.name
  
  
  class BuildingGroup(models.Model):
      description           = models.CharField(max_length=500, null=True, blank=True)
      buildings             = models.ManyToManyField(Building, default=None, blank=True)
  
  </code></pre>
  
  <p>I tried this without success:</p>
  
  <pre><code> def get(self):
          building_group = BuildingGroup.objects.get(id='id')
          qs = building_group.buildings.all()
          return qs
  </code></pre>
  
  <p>my serializer</p>
  
  <pre><code>class BuildingGroupSerializer(serializers.ModelSerializer):
  
      class Meta:
  
          model = BuildingGroup
  
          fields = (
              'description',
               .....
          )
  </code></pre>
  
  <p>I can attach a screenshot to be more clear.</p>
  
  <p>Any help is highly appreciated. Thanks in advance</p>
  
  <pre><code>Here is my full view:
  
  
  class BuildingGroupAPIView(ListAPIView):
  
      permission_classes          = [permissions.IsAdminUser]
      authentication_classes      = [SessionAuthentication]
  
      serializer_class = BuildingGroupSerializer
      passed_id = None
  
      def get_queryset(self):
          qs = BuildingGroup.objects.all()
          query = self.request.GET.get('q')
          if query is not None:
              qs = qs.filter(name=query)
          return qs
  
  
  class BuildingGroupRetrieveAPIView(RetrieveAPIView):
      serializer_class = BuildingGroupSerializer
      queryset = BuildingGroup.buildings.all()
  
      def get(self):
          building_group = BuildingGroup.objects.get(id='id')
          qs = building_group.buildings.all()
          return qs
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Kgzpf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kgzpf.png" alt="enter image description here"></a></p>