Skip to content

Loading…

Fixed #23130 -- BooleanField should not override 'blank' if choices are specified #3025

Closed
wants to merge 1 commit into from

2 participants

@tb123
  • Blank override only occurs if choices are not specified.
  • Wrote tests to check blank override with and without choices.
@timgraham
Django member

buildbot, test this please.

@timgraham
Django member

Closing per ticket.

@timgraham timgraham closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 5, 2014
  1. @tb123
Showing with 15 additions and 1 deletion.
  1. +2 −1 django/db/models/fields/__init__.py
  2. +13 −0 tests/model_fields/tests.py
View
3 django/db/models/fields/__init__.py
@@ -933,7 +933,8 @@ class BooleanField(Field):
description = _("Boolean (Either True or False)")
def __init__(self, *args, **kwargs):
- kwargs['blank'] = True
+ if 'choices' not in kwargs:
+ kwargs['blank'] = True
super(BooleanField, self).__init__(*args, **kwargs)
def check(self, **kwargs):
View
13 tests/model_fields/tests.py
@@ -363,6 +363,19 @@ def test_null_default(self):
self.assertIsNone(nb.nbfield)
nb.save() # no error
+ def test_blank_override(self):
+ """
+ Check that a BooleanField doesn't override 'blank' when
+ choices are used. (#23130)
+ """
+ # Ensure that when choices are specified, blank is not overridden
+ choices = [(True, "Special True"), (False, "Special False")]
+ f = models.BooleanField(choices=choices)
+ self.assertEqual(f.blank, False)
+ # Ensure that when choices are not specified, blank is overridden
+ f = models.BooleanField()
+ self.assertEqual(f.blank, True)
+
class ChoicesTests(test.TestCase):
def test_choices_and_field_display(self):
Something went wrong with that request. Please try again.