title: Django REST Framework ManyToMany filter multiple values
body: <p>I have two models, one defining users, the other defining labels on these users. I am using Django REST Framework to create an API. I would like to be able to query users containing at least the label ids 1 and 2.</p>
  <p>For instance if the user's labels are:
  <code>[(1,2), (1,2,3), (2,3), (1,3)]</code> I want the query to return
  <code>[(1,2), (1,2,3)]</code>.</p>
  <p>So far, I've managed to query users with a given label (let's say id=1) by doing: <code>/api/users/?labels=1</code>, but I am unable to query users with labels 1 and 2. I've tried <code>/api/users/?labels=1,2</code> or <code>/api/users/?labels=1&amp;labels=2</code> but it returns some invalid users, i.e. users without labels 1 or 2...</p>
  <p><strong>Github test repo:</strong></p>
  <p><a href="https://github.com/TheDimLebowski/drf-m2m-filter" rel="nofollow noreferrer">https://github.com/TheDimLebowski/drf-m2m-filter</a></p>
  <p><strong>Code:</strong></p>
  <h2>models.py</h2>
  <pre><code>class Label(models.Model):
      name = models.CharField(max_length = 60)
  
  class User(models.Model):
      labels = models.ManyToManyField(Label)
  </code></pre>
  <h2>filters.py</h2>
  <pre><code>class UserFilter(django_filters.FilterSet):
      labels = django_filters.filters.BaseInFilter(
          name='labels',
          lookup_type='in',
      )
  
      class Meta:
          model = User
          fields = ('labels',)
  </code></pre>
  <h2>serializers.py</h2>
  <pre><code>class LabelSerializer(serializers.ModelSerializer):
      class Meta:
          model = Label
          fields = ('id','name')
  
  class UserSerializer(serializers.ModelSerializer):
      labels = LabelSerializer(many = True)
      class Meta:
          model = User
          fields = ('labels',)
  </code></pre>
  <h2>views.py</h2>
  <pre><code>class UserViewSet(viewsets.ModelViewSet):
      queryset = User.objects.all()
      serializer_class = UserSerializer
      filter_backends = (filters.DjangoFilterBackend,)
      filter_class = UserFilter
      filter_fields = ('labels',)
  </code></pre>