Is there a widget in Django 1.0.2 to render a models.BooleanField
as two radio buttons instead of a checkbox?
Django 1.2 has added the "widgets" Meta option for modelforms:
In your models.py, specify the "choices" for your boolean field:
BOOL_CHOICES = ((True, 'Yes'), (False, 'No')) class MyModel(models.Model): yes_or_no = models.BooleanField(choices=BOOL_CHOICES)
Then, in your forms.py, specify the RadioSelect widget for that field:
class MyModelForm(forms.ModelForm): class Meta: model = MyModel widgets = { 'yes_or_no': forms.RadioSelect }
I've tested this with a SQLite db, which also stores booleans as 1/0 values, and it seems to work fine without a custom coerce function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With