class ProductFilter(django_filters.FilterSet):
label = django_filters.LookupChoiceFilter(
lookup_choices=[
('contains', 'Contains'),
('in', 'In')
]
)
class Meta:
model = Product
fields = ['label']
class ListProduct(generics.ListAPIView):
queryset = Product.objects.all()
serializer_class = ProductSerializer
filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
filter_class = ProductFilter
“ http://localhost:8000/api?label=foo&label_lookup=contains” 工作正常,但 “ http://localhost:8000/api?label=foo,bar&label_lookup=in” 返回一个空列表。我希望它返回所有包含'foo'或'bar'的记录。
我尝试了不同的方法,但无法使其起作用。有解决办法吗?