diff options
| author | Tymur Maryokhin | 2015-03-03 17:02:12 +0100 | 
|---|---|---|
| committer | Tymur Maryokhin | 2015-03-03 17:02:12 +0100 | 
| commit | 391b0ae21b29212764c4f3d079187d07228bb743 (patch) | |
| tree | 0fe27648f5314e831d1fa8f24ef1f1cc5a004258 /rest_framework | |
| parent | 5aa204e94f3173e8bc20439033a5d613625b1311 (diff) | |
| download | django-rest-framework-391b0ae21b29212764c4f3d079187d07228bb743.tar.bz2 | |
Call default.set_context() only on create. Refs #2619.
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/fields.py | 6 | 
1 files changed, 3 insertions, 3 deletions
| diff --git a/rest_framework/fields.py b/rest_framework/fields.py index c327f11b..a80862e8 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -103,7 +103,7 @@ def set_value(dictionary, keys, value):      dictionary[keys[-1]] = value -class CreateOnlyDefault: +class CreateOnlyDefault(object):      """      This class may be used to provide default values that are only used      for create operations, but that do not return any value for update @@ -114,7 +114,7 @@ class CreateOnlyDefault:      def set_context(self, serializer_field):          self.is_update = serializer_field.parent.instance is not None -        if callable(self.default) and hasattr(self.default, 'set_context'): +        if callable(self.default) and hasattr(self.default, 'set_context') and not self.is_update:              self.default.set_context(serializer_field)      def __call__(self): @@ -130,7 +130,7 @@ class CreateOnlyDefault:          ) -class CurrentUserDefault: +class CurrentUserDefault(object):      def set_context(self, serializer_field):          self.user = serializer_field.context['request'].user | 
