title: Django Rest Framework filterset on many to many field
body: <p>I'm trying to filter manytomany field by it's name field but I can't set it up properly. Could any body have a look at this?</p>
  
  <p><strong>Models</strong></p>
  
  <pre><code>class Criteria(models.Model):
      name = models.CharField(max_length=400, primary_key=True)
      tests = models.ManyToManyField(Test)
  
  class Test(models.Model):
      name = models.CharField(max_length=4000)
  </code></pre>
  
  <p><strong>Views</strong></p>
  
  <pre><code>class CriteriaViewSet(DefaultsMixin, viewsets.ModelViewSet):
      queryset = Criteria.objects.all()
      filter_class = CriteriaFilter
      filter_fields = ('tests',)
  
  
      def get_serializer_class(self):
          if self.action == 'list':
              return CriteriaSerializer
          return CriteriaDetailSerializer
  </code></pre>
  
  <p><strong>Filterset</strong></p>
  
  <pre><code>class CriteriaFilter(django_filters.FilterSet):
      test = django_filters.CharFilter(name="tests__name", lookup_type='contains')
      class Meta:
          model = Criteria
          fields = ('tests',)
  </code></pre>
  
  <p><strong>Serializers</strong></p>
  
  <pre><code>class CriteriaSerializer(serializers.ModelSerializer):
      tests = serializers.StringRelatedField(many=True)
      links = serializers.SerializerMethodField()
  
      class Meta:
          model = Criteria
          fields = ('name', 'tests', 'links')
  
      def get_links(self, obj):
          request = self.context['request']
          return {
              'self': reverse('api:criterium-detail',
              kwargs={'pk': obj.pk},
              request=request),
          }
  </code></pre>
  
  <p>With the configuration above what I get on the URL:</p>
  
  <blockquote>
    <p>/api/criteria/?test=FB1400</p>
  </blockquote>
  
  <p>is empty results array even though there is a number of Criteria containing addressed test:</p>
  
  <pre><code>HTTP 200 OK Content-Type: application/json Vary: Accept Allow: GET, POST, HEAD, OPTIONS
  
  {
      "count": 0,
      "next": null,
      "previous": null,
      "results": []
  }
  </code></pre>
  
  <p>I was trying different lookups (exact, in, contains) as well as different values in <code>fields</code> but none of those works for me...
  I was also wondering if I should set up django filter backend somewhere but I'm not sure how to do this and I don't know if it's necessary in this case.</p>