aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/fields.py
diff options
context:
space:
mode:
authorTom Christie2013-06-02 20:12:49 +0100
committerTom Christie2013-06-02 20:12:49 +0100
commitb15a6ccef2e13ab3310dbe856a945bba56e21c63 (patch)
treeeedeffadf8f6fa48d339940e8bba64e33b33db7d /rest_framework/fields.py
parent01e80ff9f77c075a01fc84c93f511a8b16ab3045 (diff)
downloaddjango-rest-framework-b15a6ccef2e13ab3310dbe856a945bba56e21c63.tar.bz2
Serializer field 'default' argument may be a callable
Diffstat (limited to 'rest_framework/fields.py')
-rw-r--r--rest_framework/fields.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index 30bbafc4..535aa2ac 100644
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -250,9 +250,6 @@ class WritableField(Field):
self.validators = self.default_validators + validators
self.default = default if default is not None else self.default
- if is_simple_callable(self.default):
- self.default = self.default()
-
# Widgets are ony used for HTML forms.
widget = widget or self.widget
if isinstance(widget, type):
@@ -298,7 +295,10 @@ class WritableField(Field):
except KeyError:
if self.default is not None and not self.partial:
# Note: partial updates shouldn't set defaults
- native = self.default
+ if is_simple_callable(self.default):
+ native = self.default()
+ else:
+ native = self.default
else:
if self.required:
raise ValidationError(self.error_messages['required'])