mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-18 04:02:35 +03:00
Add compatibility with older django/python versions
This commit is contained in:
parent
ad96159234
commit
82c42dc5db
|
@ -96,6 +96,10 @@ class SearchFilter(BaseFilterBackend):
|
||||||
if hasattr(field, "path_infos"):
|
if hasattr(field, "path_infos"):
|
||||||
# Update opts to follow the relation.
|
# Update opts to follow the relation.
|
||||||
opts = field.path_infos[-1].to_opts
|
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.
|
# Otherwise, use the field with icontains.
|
||||||
lookup = 'icontains'
|
lookup = 'icontains'
|
||||||
return LOOKUP_SEP.join([field_name, lookup])
|
return LOOKUP_SEP.join([field_name, lookup])
|
||||||
|
|
|
@ -182,7 +182,6 @@ class SearchFilterTests(TestCase):
|
||||||
|
|
||||||
request = factory.get('/', {'search': r'^\w{3}$', 'title_only': 'true'})
|
request = factory.get('/', {'search': r'^\w{3}$', 'title_only': 'true'})
|
||||||
response = view(request)
|
response = view(request)
|
||||||
print(response.data)
|
|
||||||
assert response.data == [
|
assert response.data == [
|
||||||
{'id': 3, 'title': 'zzz', 'text': 'cde'}
|
{'id': 3, 'title': 'zzz', 'text': 'cde'}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user