Created
September 24, 2020 01:26
-
-
Save toxinu/99912184adf4327c4e8699d0823c67ad to your computer and use it in GitHub Desktop.
blog/filtering-and-ordering-with-restless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class APIOrderingMixin: | |
| allowed_fields_ordering = [] | |
| ordering_field = 'order_by' | |
| def ordering(self, queryset): | |
| order_by = self.request.GET.get(self.ordering_field) | |
| if not order_by: | |
| return queryset | |
| if order_by.split('-')[-1] in self.allowed_fields_ordering: | |
| return queryset.order_by(order_by) | |
| return queryset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment