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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Cursor pagination enforces ordering of queryset since that is a mandatory requirement for it to work. The ordering applied should be unique.
ListModelMixincalls 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 theorderingattribute 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_orderingto cursor pagination class which controls if the ordering should be retained or not.get_orderingmethod to check this field and retain the ordering if set toTrueI know that
queryset.order_byis 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_orderingcode will be called.Beta Was this translation helpful? Give feedback.
All reactions