aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/fields.py
diff options
context:
space:
mode:
authorTom Christie2012-12-23 10:48:35 -0800
committerTom Christie2012-12-23 10:48:35 -0800
commit0576241b191a61cb11ac879ff24e0c1cf9a79ca9 (patch)
tree9d6a3d9c44283bea2d49255f1e17524701d37ecf /rest_framework/fields.py
parentab991199cb5825a4413e74aede874626f6ab9411 (diff)
parentf8a1256b1c006ee9ab46645a11ef19123b429a56 (diff)
downloaddjango-rest-framework-0576241b191a61cb11ac879ff24e0c1cf9a79ca9.tar.bz2
Merge pull request #523 from maspwr/related-required
RelatedField should respect self.required
Diffstat (limited to 'rest_framework/fields.py')
-rw-r--r--rest_framework/fields.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index f582a681..dd90c3f8 100644
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -351,7 +351,12 @@ class RelatedField(WritableField):
if self.read_only:
return
- value = data.get(field_name)
+ try:
+ value = data[field_name]
+ except KeyError:
+ if self.required:
+ raise ValidationError(self.error_messages['required'])
+ return
if value in (None, '') and not self.null:
raise ValidationError('Value may not be null')