summaryrefslogtreecommitdiff
path: root/django/forms/widgets.py
diff options
context:
space:
mode:
authorBasil Dubyk <samitnuk.work@gmail.com>2018-11-14 20:43:34 +0200
committerTim Graham <timograham@gmail.com>2018-11-14 13:43:34 -0500
commit35a08b8541c856a51b2ab718e0a2fe060debfa2a (patch)
tree8015438dae30388b295f4aac89aee98b6dd3edbe /django/forms/widgets.py
parentca2856fb6297378c40622521d21539097c28eb0b (diff)
Fixed #17210 -- Made NullBooleanSelect use unknown/true/false as query data.
Diffstat (limited to 'django/forms/widgets.py')
-rw-r--r--django/forms/widgets.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index e4f8957189..eed1fa5c3b 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -696,27 +696,35 @@ class NullBooleanSelect(Select):
"""
def __init__(self, attrs=None):
choices = (
- ('1', _('Unknown')),
- ('2', _('Yes')),
- ('3', _('No')),
+ ('unknown', _('Unknown')),
+ ('true', _('Yes')),
+ ('false', _('No')),
)
super().__init__(attrs, choices)
def format_value(self, value):
try:
- return {True: '2', False: '3', '2': '2', '3': '3'}[value]
+ return {
+ True: 'true', False: 'false',
+ 'true': 'true', 'false': 'false',
+ # For backwards compatibility with Django < 2.2.
+ '2': 'true', '3': 'false',
+ }[value]
except KeyError:
- return '1'
+ return 'unknown'
def value_from_datadict(self, data, files, name):
value = data.get(name)
return {
- '2': True,
True: True,
'True': True,
- '3': False,
'False': False,
False: False,
+ 'true': True,
+ 'false': False,
+ # For backwards compatibility with Django < 2.2.
+ '2': True,
+ '3': False,
}.get(value)