Fix double underscore attribute fetching.

This commit is contained in:
Nikola Kolevski 2015-08-05 10:38:40 +00:00
parent f7cd7a1c1f
commit e0608ed363

View File

@ -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):