From 539748cb69f4c239c687ed01628fc9e27ba517d9 Mon Sep 17 00:00:00 2001 From: Vlad Dragos Date: Thu, 19 Mar 2015 10:30:45 +0200 Subject: [PATCH] Add a check in CursorPagination.paginate_queryset to only apply the default the order_by method if the queryset is not ordered. --- rest_framework/pagination.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index b6be6b7cc..a9312d6ef 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -512,10 +512,11 @@ class CursorPagination(BasePagination): (offset, reverse, current_position) = self.cursor # Cursor pagination always enforces an ordering. - if reverse: - queryset = queryset.order_by(*_reverse_ordering(self.ordering)) - else: - queryset = queryset.order_by(*self.ordering) + if not queryset.ordered: + if reverse: + queryset = queryset.order_by(*_reverse_ordering(self.ordering)) + else: + queryset = queryset.order_by(*self.ordering) # If we have a cursor with a fixed position then filter by that. if current_position is not None: