2👍
From the Django documentation (https://docs.djangoproject.com/en/dev/ref/forms/widgets/):
New in Django 1.4 – For more granular control over the generated markup, you can loop over the radio buttons in the template. Assuming a form myform with a field beatles that uses a RadioSelect as its widget:
{% for radio in myform.beatles %}
<div class="myradio">
{{ radio }}
</div>
{% endfor %}
👤LukV
0👍
Why are you doing it like this? You should let the field output itself, including the selected field. If you need to set one of the choices to be selected, you should do it in the view or the form, with the initial
parameter:
context.update({
'searchForm': MultiSearchForm(initial={'mode': your_choice}),
})
- [Answered ]-Adding more associations with foreign key
- [Answered ]-Django: ValueError when saving an instance to a ForeignKey Field
- [Answered ]-URL with args does not reverse
- [Answered ]-Django – AngularJs Project Structure
- [Answered ]-404 error while trying to post using django tasty pie
Source:stackexchange.com