From 39658f1bf46b57918cfbe2a497594e3531aa1614 Mon Sep 17 00:00:00 2001 From: Mohit Mittal Date: Thu, 20 Oct 2016 07:04:54 -0700 Subject: [PATCH] allow context to be set even after initialization --- rest_framework/serializers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 4d1ed63ae..55e686efd 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -134,6 +134,14 @@ class BaseSerializer(Field): list_serializer_class = getattr(meta, 'list_serializer_class', ListSerializer) return list_serializer_class(*args, **list_kwargs) + ''' + HACK to pass context down to child serializers in rippling. + The right way might be to remove @cached_property from fields.py + and set self._context here + ''' + def set_context(self, context): + self.context = context; + def to_internal_value(self, data): raise NotImplementedError('`to_internal_value()` must be implemented.')