django's filter SearchFilter isn't filtering the results, it returns me all of the objects

Viewed 261

Im using Django and trying to filter my response data by SearchFilter

http://localhost:8000/autocomplete/a/?search=Something

the problem that it returns me all of the data objects. like there was no filter at all

http://localhost:8000/autocomplete/a/

my views.py:


from autocomplete.models import Autocomplete
from autocomplete.serializers import AutcompleteSerializer
from rest_framework import generics
from rest_framework.views import APIView
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter, SearchFilter


class AutocompleteListView(generics.ListAPIView):
    serializer_class = AutcompleteSerializer
    queryset = Autocomplete.objects.all()
    filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
    filter_fields = ("IATA", "IATAcity") # < this is working
    ordering_fields = ("AirportName") # < not working
    search_fields = ("IATA", "IATAcity") # < not working

saw possible solution here, in the last comment:

Django REST - SearchFilter not filtering

but dont really got where exactly should i post it.

what am i doing wrong?

Thanks!!

2 Answers

you can change your search_fields format tuble to list

found a solution:

make sure that on settings.py you dont have 'SEARCH_PARAM': 'SOMETHING'!!

Related