title: Django rest framework - filter many-to-many field
body: <p>Suppose I have a model like this one:</p>
  
  <pre><code>class Car(models.Model):
      images = models.ManyToManyField(Image)
  
  class Image(models.Model):
      path = models.CharField()
      type = models.CharField()
  </code></pre>
  
  <p>I want to expose two API views: </p>
  
  <ul>
  <li>cars list </li>
  <li>car details </li>
  </ul>
  
  <p>In list view I want to show only images that have type="thumbnail". In details view I want to show images of type="image".</p>
  
  <p>This is more or less what the list should look like:</p>
  
  <pre><code>[{
      "id": 1,
      "images": [1, 2],
  },
  {
      "id": 2,
      "images": [3, 4],
  }]
  </code></pre>
  
  <p>And the details view:</p>
  
  <pre><code>{
      "id": 1,
      "images": [5],
  }
  </code></pre>
  
  <p>Note that different image ids are displayed depending on the view. </p>
  
  <p>So far my serializer looks like this:</p>
  
  <pre><code>class CarSerializer(serializers.ModelSerializer):
      images = serializers.ManyPrimaryKeyRelatedField()
  
      class Meta:
          model = Car
  </code></pre>
  
  <p>List api view:</p>
  
  <pre><code>class CarList(generics.ListAPIView):
      model = Car
      serializer_class = CarSerializer
  </code></pre>
  
  <p>Details api view:</p>
  
  <pre><code>class CarDetails(generics.RetrieveAPIView):
      model = Car
      serializer_class = CarSerializer
  </code></pre>
  
  <p>This of course gives me all images in list as well as in details and forces clients to make additional calls to get image type that should be displayed.</p>
  
  <p>Is there any generic way to do it? I have seen django-filter examples, but it seems that its only possible to filter which objects are listed, not what related objects in listed objects are listed.</p>