Personnalisation de Django formes avec RadioSelect widget

Donc je suis en utilisant jQuery UI pour peau les boutons de la radio mais je ne peux pas obtenir de Django pour rendre mon formulaire de la façon qu'il a à faire.

J'ai besoin de cette structure:

<table>
    <tr>
        <td><label for="notify_new_friends">Notify when new friends join</label></td>
        <td class="radio">
            <input type="radio" name="notify_new_friends" id="notify_new_friends_immediately" value="1" checked="checked"/><label for="notify_new_friends_immediately">Immediately</label>
            <input type="radio" name="notify_new_friends" id="notify_new_friends_never" value="0"/><label for="notify_new_friends_never">Never</label>
        </td>
    </tr>
</table>

Donc, pour résumer ce que j'ai besoin de les boutons de la radio au sein d'une classe (de la radio), où ils ont un input et un label for.

Quand j'ai rendu le formulaire dans mon modèle avec {{ profile_form.notify_new_friends }} je reçois le texte suivant:

<ul>
    <li><label for="id_notify_new_friends_0"><input type="radio" id="id_notify_new_friends_0" value="0" name="notify_new_friends" /> Immediately</label></li>
    <li><label for="id_notify_new_friends_1"><input type="radio" id="id_notify_new_friends_1" value="1" name="notify_new_friends" /> Never</label></li>
</ul>

Qui est exactement ce que je veux, sauf pour la liste de pièces. J'ai donc essayé de boucler sur elle qui me donne les étiquettes de mise en forme différemment:

{% for item in profile_form.notify_new_friends %}
    {{ item }}
{% endfor %}

qui me donne:

<label><input type="radio" name="notify_new_friends" value="0" /> Immediately</label>
<label><input type="radio" name="notify_new_friends" value="1" /> Never</label>

Donc, le problème ici est qu'il cesse d'utiliser label for et commence à utiliser juste label de wrapp tout avec.

J'ai aussi essayé de faire quelque chose comme cela, mais alors le label et label_tag ne pas tout rendre.

{{ profile_form.notify_new_friends.0 }}
{{ profile_form.notify_new_friends.0.label_tag }}
{{ profile_form.notify_new_friends.0.label }}

Si quelqu'un sait comment je peux rendre cette correctement!?

Pour info, c'est mon forms.py:

self.fields['notify_new_friends'] = forms.ChoiceField(label='Notify when new friends join', widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES)
docs.djangoproject.com/en/dev/ref/forms/widgets/#radioselect - avez-vous lu cela ?
oui, mais j'avais manqué la choice_label à obtenir l'étiquette de titre, mais, malheureusement, faire {{ radio.tag }} ne pas me fournir un IDENTIFIANT et donc je ne peux pas faire label for dont j'ai besoin pour le faire.
domaine id sont générés automatiquement, essayez, {{ domaine.auto_id }}
J'ai peut-être mal compris comment l'utiliser, mais non, ça ne veut pas me donner quelque chose de rendu.

OriginalL'auteur olofom | 2012-07-19