﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22282	models.BooleanField.blank should be 'False' if BooleanField has choices	django@…	nobody	"There's no way to override the 'blank' property on a boolean field.
If you look at db/models/fields/__init__.py  under `BooleanField.__init__()` you'll see that `blank = True` is hard coded.

This gets messy for a couple of reasons:

* It means that doing something like this silently fails. Either it should raise an error (e.g. ""blank cannot be set for BooleanField"") or in `__init__` do a check to only set `blank=True` if `kwargs.get('blank')` is `None`

{{{
class MyObj(models.Model):
    is_good = models.BooleanField(blank=False) # fails silently since blank = True is hard coded
}}}


* It makes me question the strictness of the `blank` property, if a boolean field in a form can validate when in fact it is `False` and not `None` (OK, I'm assuming somewhere that BooleanField converts a `None` value to `False`?

* Most importantly (and the case where this broke for me) is when I wanted to do something like:


{{{
class MyObj(models.Model):
    is_good = models.BooleanField(choices=(
                               (False, ""Object is Bad""),
                               (True, ""Object is Good"")
                    )

}}}

There's no way to make sure the value is not blank.

My simple fix was to edit `BooleanField`'s `__init__` method to do:


{{{
    def __init__(self, *args, **kwargs):
        if not kwargs.get('choices'):
            kwargs['blank'] = True
        Field.__init__(self, *args, **kwargs)
}}}


But now I think about it maybe the fact that `BooleanField` assumes a `None` value to be `False` is another problem as well. I know why - because the default widget is a tickbox, which have the same state for `None` and `False` - but maybe the converting of `None` to `False` should consider the widget type?

"	Uncategorized	closed	Database layer (models, ORM)	1.6	Normal	needsinfo			Unreviewed	0	0	0	0	1	0
