Created
April 19, 2016 21:03
-
-
Save eezis/d7cdabdf7fed4f0e9898e1f4c8ef47f4 to your computer and use it in GitHub Desktop.
Horizontal Radio Buttons For Boolean Values Using Crispy Forms with Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Quick guide to getting inlineradio buttons when using boolean values with Crispy Forms. | |
1. create chocies | |
BOOLEAN_YN = ( | |
(True, u'Yes'), | |
(False, u'No'), | |
) | |
2. update model to point at the choices | |
under_maintenance_now = models.BooleanField(default=False, choices=BOOLEAN_YN) | |
3. Update the Field in the forms.py ModelForm (import it first) | |
from crispy_forms.bootstrap import InlineRadios | |
Div(InlineRadios('under_maintenance_now'), css_class="col-md-3"), | |
That's it, no need to mess with the widgets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment