<p>我找到了最好的答案。我可以使用客户过滤器</p>
<pre><code>from django_filters import rest_framework as restfilters
class ProductFilter(restfilters.FilterSet):
isrulendNull=restfilters.BooleanFilter(field_name='ruleend', lookup_expr='isnull')
class Meta:
model = ProductPrice
fields = ('customerid', 'customername', 'ruleend', 'productkey', 'productdescription', 'rulestart')
class ProductPriceViewSet(viewsets.ModelViewSet):
serializer_class = ProductPriceSerializer
pagination_class = pagination.PageNumberPagination
filter_backends = [DjangoFilterBackend, filters.OrderingFilter]
filterset_class = ProductFilter
# filterset_fields = ['customerid', 'customername', 'productkey', 'productdescription', 'ruleend', 'rulestart']
ordering_fields = ['customerid', 'productkey', 'rulestart']
def get_queryset(self):
self.pagination_class.page_size_query_param = 'page_size'
return ProductPrice.objects.all()
</code></pre>
<p>我将自定义字段设置为“isrulendNull”</p>
<p><a href="https://i.stack.imgur.com/oV1aK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oV1aK.png" alt="enter image description here"/></a></p>
<p>我希望这能帮助其他和我面临同样问题的人</p>