diff options
| author | Tom Christie | 2013-05-18 14:45:06 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-05-18 14:45:06 +0100 |
| commit | 304c07681d256c4e3c6e1e1485bf9b905ba431fb (patch) | |
| tree | 46c9c269d6e7b3faa8890f05e2c066420e872e55 /rest_framework/fields.py | |
| parent | 275bfa2320eeffcfd307daaf7c85faaa0f55a8ee (diff) | |
| parent | a0e3c44c99a61a6dc878308bdf0890fbb10c41e4 (diff) | |
| download | django-rest-framework-304c07681d256c4e3c6e1e1485bf9b905ba431fb.tar.bz2 | |
Merge
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 49d2a6d5..491aa7ed 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -15,6 +15,7 @@ import warnings from django.core import validators from django.core.exceptions import ValidationError from django.conf import settings +from django.db.models.fields import BLANK_CHOICE_DASH from django import forms from django.forms import widgets from django.utils.encoding import is_protected_type @@ -51,7 +52,7 @@ def get_component(obj, attr_name): return that attribute on the object. """ if isinstance(obj, dict): - val = obj[attr_name] + val = obj.get(attr_name) else: val = getattr(obj, attr_name) @@ -407,6 +408,8 @@ class ChoiceField(WritableField): def __init__(self, choices=(), *args, **kwargs): super(ChoiceField, self).__init__(*args, **kwargs) self.choices = choices + if not self.required: + self.choices = BLANK_CHOICE_DASH + self.choices def _get_choices(self): return self._choices |
