PageNumberPagination and a queryset without fixed order

40 views
Skip to first unread message

Olivier Parent-Colombel

unread,
Feb 18, 2017, 5:24:56 AM2/18/17
to Django REST framework
Hello all,

According to the documentation, nothing special is required to enable pagination when using a class inheriting from GenericAPIView. I've looked to the code of django and django rest framework and the ViewSet queryset doesn't seem ordered when using this pagination. It only adds the SQL keywords LIMIT and OFFSET to the query (using django paginator class). 

Other pagination enforces order. For example, PageNumberPagination will order the queryset (see https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/pagination.py#L467).

What I don't understand is how PageNumberPagination handles a queryset that doesn't have a deterministic order ? Why the documentation doesn't say to add a .order_by() statement at the end of the ViewSet queryset ?

I have also opened a question on stackoverflow (http://stackoverflow.com/questions/42306415/pagenumberpagination-and-a-queryset-without-fixed-order) but I only got general answers on the fact that responses to SQL query without ORDER BY keywords are not ordered.

Thank you for your help,
Reply all
Reply to author
Forward
0 new messages