1👍
✅
The field_name=…
parameter [readthedocs.io] can accept a chain of field names, like when you filter. Indeed:
Field names can traverse relationships by joining the related parts with the ORM lookup separator (
__
). e.g., a product’smanufacturer__name
.
So you can work with:
class EmployeeFilter(filters.FilterSet):
full_name = filters.CharFilter(
field_name="full_name", lookup_expr='icontains'
)
company_name = filters.CharFilter(
field_name="companyrecord__company__cname", lookup_expr='icontains'
)
class Meta:
model = Employee
fields = ['full_name']
Then you thus filter with the company_name
for that filter.
Source:stackexchange.com