'How to manually instantiate a SearchFilter in Django Rest Framework?
I have the following view but the search filter is not being applied. What am I missing?
class ListMyModelView(generics.ListAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = (SessionAuthentication,)
serializer_class = MyModelSerializer
pagination_class = StandardResultsSetPagination
filter_backends = (filters.SearchFilter,)
search_fields = ('field1', 'field2')
def get_queryset(self):
results = MyModel.objects.all()
return results.order_by('-last_modified').distinct()
def get(self, request):
paginator = self.pagination_class()
queryset = self.get_queryset()
results_page = paginator.paginate_queryset(queryset, request)
serializer = self.serializer_class(results_page, many=True)
return paginator.get_paginated_response(serializer.data)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
