class IdcViewSet(ModelViewSet):
queryset = Idc.objects.all()
serializer_class = IdcSerializer
filter_backends = (filters.SearchFilter, filters.OrderingFilter, DjangoFilterBackend) # 指定过滤器
search_fields = ('name',) # 指定可搜索的字段
filter_fields = ('name',) # 指定过滤的字段
2. 故障排除
class IdcViewSet(ModelViewSet):
queryset = Idc.objects.all()
serializer_class = IdcSerializer
filter_backends = (filters.SearchFilter, filters.OrderingFilter, DjangoFilterBackend) # 指定过滤器
search_fields = ('name',) # 指定可搜索的字段
filterset_fields = ('name',)
只是将filter_fields改为了filterset_fields,整整折腾了1整天.
就能恢复正常的过滤了