Skip to content

Commit

Permalink
fix: sorting of elements in search all
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Jan 9, 2025
1 parent 9f62270 commit f84de62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def to_representation(self, data):
This will invoke the respective custom list serializers for all the documents.
"""
iterable = data.all() if isinstance(data, models.Manager) else data
last_item = iterable[-1] if len(iterable) > 0 else None
self._context["last_item"] = last_item
view = self._context.get("view")
if view:
setattr(view, "last_item", last_item)

grouped_instances = self.group_multi_serializer_instances(iterable)

representations = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ def get_paginated_response(self, data):
Get paginated response, including search_after value for the next page.
"""
response = super().get_paginated_response(data)
last_item = data[-1] if data else None
search_after = last_item.get("sort") if last_item else None
view = self.request.parser_context.get("view")
last_item = getattr(view, "last_item", None)
search_after = last_item.meta.sort.copy() if last_item else None
next_link = response.data.pop("next", None)
response.data["next"] = search_after if next_link else None
return response
Expand Down

0 comments on commit f84de62

Please sign in to comment.