mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 17:39:48 +03:00
Fix sorting by related fields
Allow sorting by `related_field__field_name` using django notation with `__` as separator.
This commit is contained in:
parent
5b990d4092
commit
43f91f5a09
|
@ -873,7 +873,9 @@ class CursorPagination(BasePagination):
|
||||||
if isinstance(instance, dict):
|
if isinstance(instance, dict):
|
||||||
attr = instance[field_name]
|
attr = instance[field_name]
|
||||||
else:
|
else:
|
||||||
attr = getattr(instance, field_name)
|
attr = instance
|
||||||
|
for field in field_name.split('__'):
|
||||||
|
attr = getattr(attr, field)
|
||||||
return str(attr)
|
return str(attr)
|
||||||
|
|
||||||
def get_paginated_response(self, data):
|
def get_paginated_response(self, data):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user