Retain Queryset ordering when using cursor based pagination #7988
Unanswered
KushGoyal
asked this question in
Ideas & Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Cursor pagination enforces ordering of queryset since that is a mandatory requirement for it to work. The ordering applied should be unique.
ListModelMixin
calls pagination after applying all the filter backends which includes ordering filter. When cursor pagination class gets the queryset it applies the ordering filter again or uses theordering
attribute set on the class. This causes the last ordering to be applied on the queryset which is the one applied by the cursor pagination class.My suggestion is to allow the user to retain the ordering already applied at various points in the code so that cursor pagination does not override it.
2 changes are suggested:
retain_ordering
to cursor pagination class which controls if the ordering should be retained or not.get_ordering
method to check this field and retain the ordering if set toTrue
I know that
queryset.order_by
is not documented but there is no other cleaner and simple way to get the applied ordering on a queryset.I have called the super method since this code is from my custom cursor pagination class but of course in the else condition original
get_ordering
code will be called.Beta Was this translation helpful? Give feedback.
All reactions