Skip to content

Commit a74ed9f

Browse files
committed
Add compatibility with older django/python versions
1 parent 1f0f0ad commit a74ed9f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

rest_framework/filters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def construct_search(self, field_name, queryset):
9696
if hasattr(field, "path_infos"):
9797
# Update opts to follow the relation.
9898
opts = field.path_infos[-1].to_opts
99+
# django < 4.1
100+
elif hasattr(field, 'get_path_info'):
101+
# Update opts to follow the relation.
102+
opts = field.get_path_info()[-1].to_opts
99103
# Otherwise, use the field with icontains.
100104
lookup = 'icontains'
101105
return LOOKUP_SEP.join([field_name, lookup])

tests/test_filters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ class SearchListView(generics.ListAPIView):
182182

183183
request = factory.get('/', {'search': r'^\w{3}$', 'title_only': 'true'})
184184
response = view(request)
185-
print(response.data)
186185
assert response.data == [
187186
{'id': 3, 'title': 'zzz', 'text': 'cde'}
188187
]

0 commit comments

Comments
 (0)