我正在使用Django,并尝试通过SearchFilter过滤我的响应数据
返回所有数据对象的问题。就像根本没有过滤器
我的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
在最后的评论中看到了可能的解决方案:
但是我确实没有确切地发布它。
我在做什么错了?
谢谢!
答案 0 :(得分:0)
您可以将search_fields
格式的插条更改为列表
答案 1 :(得分:0)
找到了解决方案:
确保在<source>: In function 'f':
<source>:4:12: warning: declaration of 'y' shadows a global declaration [-Wshadow]
4 | void f(int y){
| ~~~~^
<source>:2:11: note: shadowed declaration is here
2 | int w, x, y, z = 10;
| ^
<source>: In function 'main':
<source>:11:9: warning: declaration of 'w' shadows a global declaration [-Wshadow]
11 | int w;
| ^
<source>:2:5: note: shadowed declaration is here
2 | int w, x, y, z = 10;
| ^
Compiler returned: 0
上没有settings.py
!