diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-04-10 19:57:11 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-04-10 19:57:11 +0000 |
| commit | 2ab40287bc8996d2cba1edd562fbe648c880ad90 (patch) | |
| tree | d1d5276fc6029577473fde9fb80bde576ac85893 /django | |
| parent | 7a283f790cabfbd95a51ed0fe06f274f7c49c04d (diff) | |
[1.0.X] Fixed #9640, #10549: BooleanFields with choices, a default, and null=False now correctly doesn't generate a blank option. Backport of r10500 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10502 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/fields/__init__.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 8da95bb4c4..7ed497cb09 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -393,7 +393,13 @@ class BooleanField(Field): return bool(value) def formfield(self, **kwargs): - defaults = {'form_class': forms.BooleanField} + # Unlike most fields, BooleanField figures out include_blank from + # self.null instead of self.blank. + if self.choices: + include_blank = self.null or not (self.has_default() or 'initial' in kwargs) + defaults = {'choices': self.get_choices(include_blank=include_blank)} + else: + defaults = {'form_class': forms.BooleanField} defaults.update(kwargs) return super(BooleanField, self).formfield(**defaults) |
