Setting ID for Radio buttons in Django

django

Solution

While debuging a RadioSelect rendering, I got no idea of using radio tag and label elegantly. So here is my attempt to solve your problem:

{% for radio in form.important_client reversed %}
    <input name="{{ radio.name }}" type="radio" id="radio_{{ radio.index }}" value={{ radio.choice_value }}>
    <label for="radio_{{ radio.index }}">{{ radio.choice_label }}</label>
{% endfor %}

Instead of `radio.index` property, which is not documented, you can use `forloop.counter`.

Just in case I attach a screenshot of debug window, where example of `radio` context is shown (`form_of_field` variable on a figure):

Problem

It is great that Django 1.4 allows fine graining of radio select ``` {% for radio in form.important_client reversed%} {{radio.tag}}<label for="????">{{radio.choice_label}}</label> {% endfor %} ``` but for some odd reason when using this methodology, the `<input>` have no IDs. And hence I can't set the `<label for='ID' />` accordingly. That causes big issues in my CSS. Is there anyway to get the IDs set nonetheless?

Original source