是否可以将Search过滤器与FillterSet过滤器结合使用,后者的查找表达式不是“ exact”?

时间:2019-05-26 19:41:23

标签: django-rest-framework django-filter

我想将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将被禁用。

0 个答案:

没有答案