There is a BooleanField in my Django form that I would like to have an initial value of True, so I defined it as:
my_checkbox = forms.BooleanField(label='My Checkbox', help_text='Some help text here', initial=True)
In my helper, I have:
helper.layout = Layout(
Field('my_checkbox', template="custom.html")
Custom.html looks like:
<input class="checkboxinput" id="id_{{ field.name }}" name="{{ field.name }}" type="checkbox">
<span id="hint_id_{{ field.name }}" class="help-inline">{{ field.help_text }}</span>
I tried outputting the value of field.initial, but nothing shows up. I know that if I were coding this manually, I would just put <input ... checked>
, and the box would be checked.
Is there some way to access the "initial" part of the field and set it in my custom template? Thanks!
You can access the initial data of the form field using
{{field.value}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With