Django: Display boolean field as True/False radio buttons

This sounds like such a trivial thing to do but it wasn't the most logical.

imageAlright, you'll need a tuple that contains the True/False value and labels and then a ChoiceField which uses it.

class CustomForm(forms.Form):
BOOLEAN_CHOICES = (('1', 'True label'), ('0', 'False label'))
# Filtering fields
is_true = forms.ChoiceField(choices = BOOLEAN_CHOICES, widget = forms.RadioSelect)

Oh what? We're done!



Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog