From b7abf14d3a4b78da25f303685b8cc1ccd8912b44 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 23 Jan 2013 07:38:13 +0000 Subject: [PATCH] Pass PaginationSerializer context through to child ModelSerializer on init. Fixes #595. Fixes #552. --- rest_framework/pagination.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index d241ade7c..5755a235d 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -62,7 +62,13 @@ class BasePaginationSerializer(serializers.Serializer): super(BasePaginationSerializer, self).__init__(*args, **kwargs) results_field = self.results_field object_serializer = self.opts.object_serializer_class - self.fields[results_field] = object_serializer(source='object_list') + + if 'context' in kwargs: + context_kwarg = {'context': kwargs['context']} + else: + context_kwarg = {} + + self.fields[results_field] = object_serializer(source='object_list', **context_kwarg) def to_native(self, obj): """