我想将Search过滤器与没有git标准lookup_expression的FIlterSet过滤器结合使用。
我尝试为端点添加此配置:
filter_backends = (filters.SearchFilter, DjangoFilterBackend)
search_fields = ('username', 'full_name')
filterset_fields = 'username',
工作正常,但我需要在startswith
中为username
查找filterset_fields
这是我的终点
class UsersAPIView(generics.ListAPIView):
serializer_class = CreatorSerializer
filter_backends = (filters.SearchFilter, DjangoFilterBackend)
search_fields = ('username', 'full_name')
filterset_fields = 'username',
queryset = User.objects.all()
#filter_class = UserFilter
还有我的过滤器:
class UserFilter(filters.FilterSet, ):
username = filters.CharFilter(field_name='username', lookup_expr='startswith')
class Meta:
model = User
fields = 'username',
如果我将开始使用UserFilter,则SearchFilter将被禁用。