I have a very simple ListAPIView
:
class MyListView(ListAPIView):
pagination_class = QueryParamPagination
serializer_class = MyListSerializer
queryset = MyObject.objects.all()
with a simple class to define the pagination:
class QueryParamPagination(PageNumberPagination):
page_size = 2
page_size_query_param = "page_size"
max_page_size = 27
However in this scenario I will get a warning, because the result is not ordered: inconsistent results with an unordered object_list: <class 'models.MyObject'> MultilingualSoftDeleteQuerySet.
Which is fine ...
Now changing the last line to
queryset = MyObject.objects.order_by('category', 'name').all()
gets rid of the warning, however now my pagination is not working anymore. Django now uses some super defaults, all values in QueryParamPagination
are ignored, but also my global settings
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 2,
}
Changing it again to
queryset = MyObject.objects.order_by('name').all()
works fine again. Is it not possible to use "double sorting" together with pagination?