diff options
| author | Mark Aaron Shirley | 2012-12-21 11:33:01 -0800 |
|---|---|---|
| committer | Mark Aaron Shirley | 2012-12-21 11:33:01 -0800 |
| commit | f8a1256b1c006ee9ab46645a11ef19123b429a56 (patch) | |
| tree | 16bfbc37cdb906604c0ff771c159fa6ab59279c4 /rest_framework/fields.py | |
| parent | 2f5582a1a6d8a79bfab7ffbc2d8b602fdae8e640 (diff) | |
| download | django-rest-framework-f8a1256b1c006ee9ab46645a11ef19123b429a56.tar.bz2 | |
Update RelatedField#field_from_native coding style
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 1059df91..dd90c3f8 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -351,13 +351,13 @@ 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: + try: + value = data[field_name] + except KeyError: + if self.required: + raise ValidationError(self.error_messages['required']) return - value = data.get(field_name) - if value in (None, '') and not self.null: raise ValidationError('Value may not be null') elif value in (None, '') and self.null: |
