Check if RelatedField is required.

This commit is contained in:
Mark Aaron Shirley 2012-12-19 09:26:40 -08:00
parent c13f132a21
commit 5c680c36e4

View File

@ -351,6 +351,11 @@ class RelatedField(WritableField):
if self.read_only:
return
if field_name not in data and self.required:
raise ValidationError(self.error_messages['required'])
elif field_name not in data:
return
value = data.get(field_name)
if value in (None, '') and not self.null: