aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/fields.py
diff options
context:
space:
mode:
authorTom Christie2012-12-07 21:32:39 +0000
committerTom Christie2012-12-07 21:32:45 +0000
commit303bc7cf95033d2560668bf6f4d97f05f1268967 (patch)
tree7bfd4b12df5f8e1dd9109bbfffbc0ce3c604b041 /rest_framework/fields.py
parenta5178e9a363d00f3eef8d86da2d0ec687518f288 (diff)
downloaddjango-rest-framework-303bc7cf95033d2560668bf6f4d97f05f1268967.tar.bz2
Support nullable FKs, with blank=True
Diffstat (limited to 'rest_framework/fields.py')
-rw-r--r--rest_framework/fields.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index c28a9695..bffc0fb0 100644
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -350,7 +350,13 @@ class RelatedField(WritableField):
return
value = data.get(field_name)
- into[(self.source or field_name)] = self.from_native(value)
+
+ if value is None and not self.blank:
+ raise ValidationError('Value may not be null')
+ elif value is None and self.blank:
+ into[(self.source or field_name)] = None
+ else:
+ into[(self.source or field_name)] = self.from_native(value)
class ManyRelatedMixin(object):