mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Fix double underscore attribute fetching.
This commit is contained in:
parent
f7cd7a1c1f
commit
e0608ed363
|
@ -713,7 +713,22 @@ class CursorPagination(BasePagination):
|
||||||
return tuple(ordering)
|
return tuple(ordering)
|
||||||
|
|
||||||
def _get_position_from_instance(self, instance, ordering):
|
def _get_position_from_instance(self, instance, ordering):
|
||||||
attr = getattr(instance, ordering[0].lstrip('-'))
|
attr_path = ordering[0].lstrip('-')
|
||||||
|
object_names = attr_path.split("__")
|
||||||
|
attr_name = object_names[-1]
|
||||||
|
|
||||||
|
# cut off the attribute name
|
||||||
|
object_names = object_names[:-1]
|
||||||
|
|
||||||
|
# start with the instance itself
|
||||||
|
obj = instance
|
||||||
|
|
||||||
|
# fetch any other object
|
||||||
|
for object_name in object_names:
|
||||||
|
obj = getattr(obj, object_name)
|
||||||
|
|
||||||
|
# and get the last split as the attribute
|
||||||
|
attr = getattr(obj, attr_name)
|
||||||
return six.text_type(attr)
|
return six.text_type(attr)
|
||||||
|
|
||||||
def get_paginated_response(self, data):
|
def get_paginated_response(self, data):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user