diff options
| author | Tom Christie | 2012-11-16 13:45:27 -0800 |
|---|---|---|
| committer | Tom Christie | 2012-11-16 13:45:27 -0800 |
| commit | 9973cf329a2133a900256b53236348ef3c870842 (patch) | |
| tree | 51dc6ace4f81f6137a2c8249b2ba8f88e8531480 /rest_framework/mixins.py | |
| parent | 8d3581f4bd9b0abbf88a7713a1cb8b67f820602a (diff) | |
| parent | a701a21587a69ed959533cbcfdaa9c63337c3ccc (diff) | |
| download | django-rest-framework-9973cf329a2133a900256b53236348ef3c870842.tar.bz2 | |
Merge pull request #412 from minddust/custom_page_size_per_request
support for custom page size per request
Diffstat (limited to 'rest_framework/mixins.py')
| -rw-r--r-- | rest_framework/mixins.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 53c4d984..0da4c2cc 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -7,6 +7,7 @@ which allows mixin classes to be composed in interesting ways. from django.http import Http404 from rest_framework import status from rest_framework.response import Response +from rest_framework.settings import api_settings class CreateModelMixin(object): @@ -39,6 +40,7 @@ class ListModelMixin(object): Should be mixed in with `MultipleObjectAPIView`. """ empty_error = u"Empty list and '%(class_name)s.allow_empty' is False." + page_size_kwarg = api_settings.PAGE_SIZE_KWARG def list(self, request, *args, **kwargs): queryset = self.get_queryset() @@ -64,6 +66,17 @@ class ListModelMixin(object): return Response(serializer.data) + def get_paginate_by(self, queryset): + if self.page_size_kwarg is not None: + page_size_kwarg = self.request.QUERY_PARAMS.get(self.page_size_kwarg) + if page_size_kwarg: + try: + page_size = int(page_size_kwarg) + return page_size + except ValueError: + pass + return super(ListModelMixin, self).get_paginate_by(queryset) + class RetrieveModelMixin(object): """ |
