运行此代码时,我在django rest-framework视图的过滤器弹出窗口中得到 [无效名称] 。
我想显示名称“查找” 。 我该如何设置这个名字?
class MyModelFilter(filters.FilterSet):
search_name = filters.CharFilter(field_name='name', lookup_expr='icontains')
find_anywhere = filters.CharFilter(method='look_anywhere')
def look_anywhere(self, queryset, name, value):
return queryset.filter(Q(name__icontains=value) | Q(description__icontains=value))
class Meta:
model = MyModel
fields = {'search', 'find_anywhere'}
致电
/api/mymodels/?find_anywhere=something
它工作正常。
它只是DRF视图中过滤器的名称:
答案 0 :(得分:3)
search_name = filters.CharFilter(field_name='name', lookup_expr='icontains', label="Put Label Here")