1👍
✅
Try to use self.queryset
in filter_queryset()
method inside get()
method so:
from rest_framework.views import APIView
class MyAPIView(APIView):
queryset = MyObject.objects.all()
filter_backends = [MyCustomFilterBackend, DjangoFilterBackend]
filterset_fields = ["field1", "field2"]
def filter_queryset(self, queryset):
for backend in list(self.filter_backends):
queryset = backend().filter_queryset(self.request, queryset, self)
return queryset
def get(self, request):
queryset = self.filter_queryset(self.queryset)
s = StatManager(queryset)
return Response(s.dashboard())
Source:stackexchange.com