Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom rendering a radioselect in django form / accessing single element?

I have a form like this:

CHOICES = [  
           ('a', 'a_value'),  
           ('b', 'b_value'),  
           ('c', 'c_value')  
]  

self.fields["choice"] = forms.ChoiceField(  
    widget=RadioSelect(),  
    choices=CHOICES,   
)  

How can I select a single element of this form field in my template? I want to be able to do something like:

<tr><td>{{form.choice.a}}</td><td>some custom extra field</td></tr>

Or is there another way to change how the RadioSelect is rendered?

like image 415
Oli Avatar asked Dec 28 '22 14:12

Oli


1 Answers

See full doc - https://docs.djangoproject.com/en/dev/ref/forms/widgets/#radioselect

{% for radio in form.my_radio_select %}
- {{ radio.choice_label }}
- {{ radio.tag }}
{% endfor %}
like image 172
satels Avatar answered Jan 17 '23 11:01

satels