When I run this code I get [invalid name]: in the filters popup in django rest-framework views.
I would like to display the name "find" instead. How can I set this name?
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'}
when calling
/api/mymodels/?find_anywhere=something
it works fine.
It is only the name of the filter in the DRF views:

search_name = filters.CharFilter(field_name='name', lookup_expr='icontains', label="Put Label Here")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With