Skip to content

Instantly share code, notes, and snippets.

@eezis
Created April 19, 2016 21:03
Show Gist options
  • Save eezis/d7cdabdf7fed4f0e9898e1f4c8ef47f4 to your computer and use it in GitHub Desktop.
Save eezis/d7cdabdf7fed4f0e9898e1f4c8ef47f4 to your computer and use it in GitHub Desktop.
Horizontal Radio Buttons For Boolean Values Using Crispy Forms with Django
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