diff options
| author | Tom Christie | 2015-01-05 14:32:12 +0000 |
|---|---|---|
| committer | Tom Christie | 2015-01-05 14:32:12 +0000 |
| commit | b6ca7248ebcf95a95e1911aa0b130f653b8bf690 (patch) | |
| tree | 3da53011f0e215da5e13efcaf39223f88edfefce /rest_framework/fields.py | |
| parent | 8cf37449715c32c4a692667814466c7f32e8734f (diff) | |
| download | django-rest-framework-b6ca7248ebcf95a95e1911aa0b130f653b8bf690.tar.bz2 | |
required=False allows omission of value for output. Closes #2342
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index aab80982..cc9410aa 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -288,6 +288,8 @@ class Field(object): try: return get_attribute(instance, self.source_attrs) except (KeyError, AttributeError) as exc: + if not self.required and self.default is empty: + raise SkipField() msg = ( 'Got {exc_type} when attempting to get a value for field ' '`{field}` on serializer `{serializer}`.\nThe serializer ' |
