summaryrefslogtreecommitdiff
path: root/django/forms/fields.py
diff options
context:
space:
mode:
authorKit La Touche <kit@simpleenergy.com>2014-07-29 11:04:13 -0600
committerTim Graham <timograham@gmail.com>2014-07-29 19:55:55 -0400
commit17e75d03f92cff7d1d5d4679a8a09b13e08f3264 (patch)
treea453021f7f0a254599d767acb2a660431708a1d6 /django/forms/fields.py
parent096a5de5d2bf564f859eca115874f5643ef31658 (diff)
Fixed #23129 -- Added 'true' and 'false' to `NullBooleanField`.
JavaScript serializations of forms will sometimes render the boolean values as the strings 'true' and 'false', in lower case. Rather than repeat boilerplate in the JavaScript to circumvent this, it seems reasonable to allow Django to understand the lower-case versions of the booleans.
Diffstat (limited to 'django/forms/fields.py')
-rw-r--r--django/forms/fields.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index ab746e4971..9070963607 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -753,13 +753,15 @@ class NullBooleanField(BooleanField):
def to_python(self, value):
"""
Explicitly checks for the string 'True' and 'False', which is what a
- hidden field will submit for True and False, and for '1' and '0', which
- is what a RadioField will submit. Unlike the Booleanfield we need to
- explicitly check for True, because we are not using the bool() function
+ hidden field will submit for True and False, for 'true' and 'false',
+ which are likely to be returned by JavaScript serializations of forms,
+ and for '1' and '0', which is what a RadioField will submit. Unlike
+ the Booleanfield we need to explicitly check for True, because we are
+ not using the bool() function
"""
- if value in (True, 'True', '1'):
+ if value in (True, 'True', 'true', '1'):
return True
- elif value in (False, 'False', '0'):
+ elif value in (False, 'False', 'false', '0'):
return False
else:
return None