This is how I went about, to display a Boolean model field in the form as Radio buttons Yes and No.
choices = ( (1,\'Yes\'),
(0,\'No\'),
)
Use TypedChoiceField
.
class EmailEditForm(forms.ModelForm):
to_send_form = forms.TypedChoiceField(
choices=choices, widget=forms.RadioSelect, coerce=int
)
Use this if you want the horizontal renderer.
http://djangosnippets.org/snippets/1956/
field = BooleanField(widget=RadioSelect(choices=YES_OR_NO), required=False)
YES_OR_NO = (
(True, 'Yes'),
(False, 'No')
)
If you want to deal with boolean values instead of integer values then this is the way to do it.
forms.TypedChoiceField(
choices=((True, 'Yes'), (False, 'No')),
widget=forms.RadioSelect,
coerce=lambda x: x == 'True'
)