aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/pagination.py
diff options
context:
space:
mode:
authorTom Christie2013-01-26 20:54:41 +0000
committerTom Christie2013-01-26 20:54:41 +0000
commita51bca32fd26ae954228b9026b18ebeea81ad8e2 (patch)
treed7853e6d1af3d90ee897153915fe1fc69c647cc7 /rest_framework/pagination.py
parentb41f258ee548e6746f15ad0829f6d29a5b66aefd (diff)
downloaddjango-rest-framework-a51bca32fd26ae954228b9026b18ebeea81ad8e2.tar.bz2
Fix issues with custom pagination serializers
Diffstat (limited to 'rest_framework/pagination.py')
-rw-r--r--rest_framework/pagination.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py
index 5755a235..92d41e0e 100644
--- a/rest_framework/pagination.py
+++ b/rest_framework/pagination.py
@@ -34,6 +34,17 @@ class PreviousPageField(serializers.Field):
return replace_query_param(url, self.page_field, page)
+class DefaultObjectSerializer(serializers.Field):
+ """
+ If no object serializer is specified, then this serializer will be applied
+ as the default.
+ """
+
+ def __init__(self, source=None, context=None):
+ # Note: Swallow context kwarg - only required for eg. ModelSerializer.
+ super(DefaultObjectSerializer, self).__init__(source=source)
+
+
class PaginationSerializerOptions(serializers.SerializerOptions):
"""
An object that stores the options that may be provided to a
@@ -44,7 +55,7 @@ class PaginationSerializerOptions(serializers.SerializerOptions):
def __init__(self, meta):
super(PaginationSerializerOptions, self).__init__(meta)
self.object_serializer_class = getattr(meta, 'object_serializer_class',
- serializers.Field)
+ DefaultObjectSerializer)
class BasePaginationSerializer(serializers.Serializer):
@@ -70,13 +81,6 @@ class BasePaginationSerializer(serializers.Serializer):
self.fields[results_field] = object_serializer(source='object_list', **context_kwarg)
- def to_native(self, obj):
- """
- Prevent default behaviour of iterating over elements, and serializing
- each in turn.
- """
- return self.convert_object(obj)
-
class PaginationSerializer(BasePaginationSerializer):
"""