Reputation: 553
I have implemented "PageNumber" Pagination in Django Rest framework which is working fine locally. But the same code deployed on remote server not returning results with pagination.
Pagination Class:
class MyPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
max_page_size = 20
View using Pagination:
class GetMyListings(generics.ListAPIView):
serializer_class = serializers.MyListingSerializer
pagination_class = utils.MyPagination
permission_classes = (
permissions.IsAuthenticated,
)
def get_queryset(self):
order_by_clause = self.request.GET.get('order_by', '-posted_on')
posted_clause = self.request.GET.get('posted', None)
if posted_clause:
return models.Post.objects.filter(owner=self.request.user,
is_posted=utils.make_boolean(posted_clause)
).order_by(order_by_clause)
return models.Post.objects.filter(owner=self.request.user).order_by(order_by_clause)
Upvotes: 2
Views: 1353
Reputation: 553
Problem Resolved, DRF's local version was 3.3.2
where as server had 3.1.0
because the Custom Django Paginator in PageNumberPagination
is allowed in version 3.3.2
or later.
For reference, see Release notes: http://www.django-rest-framework.org/topics/release-notes/#332
Upvotes: 3