aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/fields.py
diff options
context:
space:
mode:
authorPablo Recio2013-05-18 12:40:25 +0200
committerPablo Recio2013-05-18 12:41:52 +0200
commitab8bd566f9db327a4c463317011818d421bbf89c (patch)
tree0ee831228591b1a7ad10636539d1f6592ba6f6a1 /rest_framework/fields.py
parentde5cc8de423a22009d2a643f6c268805f715b212 (diff)
downloaddjango-rest-framework-ab8bd566f9db327a4c463317011818d421bbf89c.tar.bz2
Adding `BLANK_CHOICE_DASH` as a choice if the model's field isn't required
Diffstat (limited to 'rest_framework/fields.py')
-rw-r--r--rest_framework/fields.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index c83ee5ec..7fd4c638 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
@@ -402,6 +403,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