16👍
✅
Use TypedChoiceField
.
class EmailEditForm(forms.ModelForm):
to_send_form = forms.TypedChoiceField(
choices=choices, widget=forms.RadioSelect, coerce=int
)
6👍
field = BooleanField(widget=RadioSelect(choices=YES_OR_NO), required=False)
YES_OR_NO = (
(True, 'Yes'),
(False, 'No')
)
👤mpen
- Is there a way to check whether a related object is already fetched?
- Is it ok to catch and reraise an exception inside Django transaction.atomic()?
- Django-admin.py startproject opens notepad, instead of creating a project
2👍
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'
)
👤jhrr
Source:stackexchange.com