[Solved]-Django Rest Framework (GET filter on ManyToMany field)


Well, I found out what I was doing wrong. It was in the view. I had not declared filter_class on the view:

from rest_framework.generics import ListAPIView, RetrieveAPIView
from .serializers import StateSerializer
from .filters import StateFilter

class StateList(ListAPIView):
    queryset = State.objects.all()
    serializer_class = StateSerializer
    filter_fields = ('name', 'cities')
    filter_class = StateFilter  # This was missing

I accidentally placed it on the serializer instead.

Leave a comment