diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 01437f0f3..375242b6b 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -96,6 +96,10 @@ class SearchFilter(BaseFilterBackend): if hasattr(field, "path_infos"): # Update opts to follow the relation. opts = field.path_infos[-1].to_opts + # django < 4.1 + elif hasattr(field, 'get_path_info'): + # Update opts to follow the relation. + opts = field.get_path_info()[-1].to_opts # Otherwise, use the field with icontains. lookup = 'icontains' return LOOKUP_SEP.join([field_name, lookup]) diff --git a/tests/test_filters.py b/tests/test_filters.py index f8eed4b97..2a87165ca 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -182,7 +182,6 @@ class SearchFilterTests(TestCase): request = factory.get('/', {'search': r'^\w{3}$', 'title_only': 'true'}) response = view(request) - print(response.data) assert response.data == [ {'id': 3, 'title': 'zzz', 'text': 'cde'} ]