mirror of https://github.com/django/django.git
Removed code that assumed BooleanField could be null.
Such a field will no longer pass model validation.
This commit is contained in:
parent
21d0ceefb5
commit
fcd42a4819
|
@ -997,8 +997,7 @@ class BooleanField(Field):
|
||||||
# Unlike most fields, BooleanField figures out include_blank from
|
# Unlike most fields, BooleanField figures out include_blank from
|
||||||
# self.null instead of self.blank.
|
# self.null instead of self.blank.
|
||||||
if self.choices:
|
if self.choices:
|
||||||
include_blank = (self.null or
|
include_blank = not (self.has_default() or 'initial' in kwargs)
|
||||||
not (self.has_default() or 'initial' in kwargs))
|
|
||||||
defaults = {'choices': self.get_choices(include_blank=include_blank)}
|
defaults = {'choices': self.get_choices(include_blank=include_blank)}
|
||||||
else:
|
else:
|
||||||
defaults = {'form_class': forms.BooleanField}
|
defaults = {'form_class': forms.BooleanField}
|
||||||
|
|
|
@ -259,9 +259,6 @@ class BooleanFieldTests(unittest.TestCase):
|
||||||
formfield with the blank option (#9640, #10549).
|
formfield with the blank option (#9640, #10549).
|
||||||
"""
|
"""
|
||||||
choices = [(1, 'Si'), (2, 'No')]
|
choices = [(1, 'Si'), (2, 'No')]
|
||||||
f = models.BooleanField(choices=choices, default=1, null=True)
|
|
||||||
self.assertEqual(f.formfield().choices, [('', '---------')] + choices)
|
|
||||||
|
|
||||||
f = models.BooleanField(choices=choices, default=1, null=False)
|
f = models.BooleanField(choices=choices, default=1, null=False)
|
||||||
self.assertEqual(f.formfield().choices, choices)
|
self.assertEqual(f.formfield().choices, choices)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue