Django 1.2 added a widget option for models:
In your models.py, specify a "choice" for your boolean field:
BOOL_CHOICES = ((True, 'Yes'), (False, 'No')) class MyModel(models.Model): yes_or_no = models.BooleanField(choices=BOOL_CHOICES)
Then, in the forms.py file, specify the RadioSelect widget for this field:
class MyModelForm(forms.ModelForm): class Meta: model = MyModel widgets = { 'yes_or_no': forms.RadioSelect }
I tested this with SQLite db, which also stores booleans as 1/0 values, and it seems to work fine without using a special coercion function.
eternicode Oct 18 2018-10-18 16:16
source share