Opened 9 years ago
Closed 6 years ago
#26168 closed Cleanup/optimization (fixed)
BooleanField is forced to be blank=True
Reported by: | fengyehong | Owned by: | Lynn Cyrin |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | BooleanField |
Cc: | jonas@…, Kamil Gałuszka | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
https://github.com/django/django/tree/master/django/db/models/fields#L1017
def __init__(self, *args, **kwargs): kwargs['blank'] = True super(BooleanField, self).__init__(*args, **kwargs)
blank is set to True forcibly
I want my BooleanField always explicitly set(without a default value), like this:
myflag = models.BooleanField(blank=False)
but with this kwargs['blank'] =True
, Django does not complain if field myflag
not set, but try to use default of BooleanField(in 1.7.5, None) which lead to exception when saving~
I think force blank = True makes sense for NullBooleanField, but for BooleanField, we can leave it to user.
Thanks.
Change History (6)
comment:1 by , 9 years ago
Summary: | Django forcibly allow BooleanField blank → BooleanField is forced to be blank=True |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 9 years ago
There's an outdated patch in #23130, which I still think is the best solution to this problem. Somehow, I've never gotten around to finishing the patch, but I think it should take no more than an hour of time to get it up to date and pass the test suite.
comment:3 by , 9 years ago
Cc: | added |
---|
comment:4 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 6 years ago
Cc: | added |
---|
I think this was fixed with https://github.com/django/django/pull/8467 and #29227 . This ticket can be close then?
comment:6 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
See #22282 and #23130 for some related discussion. I'm not sure what the proper resolution is, but I'll accept the ticket since this this has come up several time. We can at least document the reasons for this if it can't be changed for backwards compatibility reasons.