Ticket #10549: fixed-choices-handling-of-BooleanFields.patch

File fixed-choices-handling-of-BooleanFields.patch, 770 bytes (added by Sebastian Noack, 16 years ago)
  • django/django/db/models/fields/__init__.py

    diff --git a/django/django/db/models/fields/__init__.py b/django/django/db/models/fields/__init__.py
    index afa1c13..fc5c968 100644
    a b class BooleanField(Field):  
    393393        return bool(value)
    394394
    395395    def formfield(self, **kwargs):
    396         defaults = {'form_class': forms.BooleanField}
     396        if self.choices:
     397            include_blank = self.null or not (self.has_default() or 'initial' in kwargs)
     398            defaults = {'choices': self.get_choices(include_blank=include_blank)}
     399        else:
     400            defaults = {'form_class': forms.BooleanField}
    397401        defaults.update(kwargs)
    398402        return super(BooleanField, self).formfield(**defaults)
    399403
Back to Top