7👍
This basically doesn’t work because you’re trying to do too much. You’ve written your own get
method which bypasses all the magic of the DRF views. In particular, by not calling GenericAPIView.get_object
, you avoid a line that looks like
queryset = self.filter_queryset(self.get_queryset())
which is where the QuerySet is filtered. This simpler version, practically identical to the one in the SearchFilter docs, should work
from rest_framework import status, filters, generics
class JobView(generics.LisaAPIView):
queryset = Job.manager.all()
serializer_class = JobSerializer
filter_backends = [filters.SearchFilter]
search_fields = ['name']
NOTE based on your question, I am assuming:
-
that your
Job
model has aname
field -
that for some reason you’ve renamed the
Job
manager tomanager
via a call tomodels.Manager()
0👍
I think you should filter your queryset based on the parameter you’re sending via GET, because it wont happen automatically. use request.query_params.get('search')
to access your parameter.
- [Django]-RawPostDataException: You cannot access body after reading from request's data stream
- [Django]-How can I get current logged User id in Django Admin Panel?
- [Django]-How to get the IP address of a client using aiohttp
- [Django]-Avoid username field creation in custom user model for django allauth
- [Django]-Access denied issue when I try to access a shared drive from Django running in Apache
Source:stackexchange.com