I'm in the process of trying to minimize the amount of code I need to use to render a form with bootstrap styling with the hope of rendering with just {{ form }} but I haven't yet managed to find a way to render a BooleanField with the checkbox before the text.
from django.forms import Form, BooleanField
class MyForm(Form):
field = BooleanField(label='Test Label')
MyForm().as_table()
The above test code will output
<tr><th><label for="id_field">Test Label:</label></th><td><input class="" id="id_field" name="field" type="checkbox" /></td></tr>
But what I'm hoping to achieve is the same look and feel as shown in the bootstrap docs.
<label for="id_field"><input class="" id="id_field" name="field" type="checkbox" />Test Label:</label>
The problem in doing this is that the rendering is handled via the form, where the label and the field are positioned/rendered separately as shown in the source, , and I have yet to find a place to override that will allow me to render the widget inside of the label...
Any ideas how I can achieve this?
I was hoping to find a way to do this with native django if possible
Yea I've heard of it. Have they managed to achieve this? I'd be interested to see how they've done it if so...I was hoping to find a way to do this with native django if possible
CheckboxInput
Widget, and in the new widget overide the render method - but there looks like a lot of deep Django Magic in that method : https://docs.djangoproject.com/en/1.9/_modules/django/forms/widgets/#CheckboxInput