From 26ac2656e5e0b3d01a67551910113a305d2a2820 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 5 Jan 2015 16:20:15 +0000 Subject: [PATCH] Pass init arguments through to serializer from pagination serializer. Closes #2355. Normally a serializer won't need these arguments on __init__, but if a user has customized __init__ they may expect them to be available. --- rest_framework/pagination.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index f31e5fa4c..9c8dda8f9 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -37,16 +37,13 @@ class PreviousPageField(serializers.Field): return replace_query_param(url, self.page_field, page) -class DefaultObjectSerializer(serializers.ReadOnlyField): +class DefaultObjectSerializer(serializers.Serializer): """ If no object serializer is specified, then this serializer will be applied as the default. """ - - def __init__(self, source=None, many=None, context=None): - # Note: Swallow context and many kwargs - only required for - # eg. ModelSerializer. - super(DefaultObjectSerializer, self).__init__(source=source) + def to_representation(self, value): + return value class BasePaginationSerializer(serializers.Serializer): @@ -74,10 +71,9 @@ class BasePaginationSerializer(serializers.Serializer): list_serializer_class = serializers.ListSerializer self.fields[results_field] = list_serializer_class( - child=object_serializer(), + child=object_serializer(*args, **kwargs), source='object_list' ) - self.fields[results_field].bind(field_name=results_field, parent=self) class PaginationSerializer(BasePaginationSerializer):