I have custom filter to my viewset:
class OrderFilter(django_filters.rest_framework.FilterSet):
username = django_filters.CharFilter(name='user__username', lookup_expr='icontains')
client_name = django_filters.CharFilter(name='user__first_name', lookup_expr='icontains')
class Meta:
model = Order
exclude = ['pk']
And it works when I send query like this:
http://localhost:8000/orders/?username=testuser
or
http://localhost:8000/orders/?client_name=john
but I want to create only one query to search data containing search string in username
, first_name
and last_name
. How to do it?
The general catch-all for complicated behavior that can't be expressed by a single filter is to use the
method
argument to a filter class (docs).A possible implementation: