Display radio button in django?

3

Hi, I have this problem ... I can not manage to display the radio button in the template ... in which I'm wrong?

models.py

class Genero(models.Model):

    MASCULINO ='mas'

    FEMENINO ='fem'
    Type_CHOICES = (
    (MASCULINO,'masculino'),
    (FEMENINO,'femenino'))
    sexo = models.CharField(choices=Type_CHOICES,default=MASCULINO, max_length=100)

form.py

class VideoForm(forms.ModelForm):

    class Meta:
        model=Genero
        fields=['sexo']
        widgets = {
        'sexo': forms.RadioSelect(choices=Video.Type_CHOICES)           

}

template

{% for radio in sexo %}

    <label >
        {{ radio }}
        <span> {{ radio.tag }} </span>
    </label>

{% endfor %}
    
asked by Gerson 05.02.2017 в 02:14
source

1 answer

0

For the form you do not need to iterate over your options, just put

{{ sexo }}

Although it sounds strange to me that you pass the variable directly like this, it should not be for example:

{{ form.sexo }}
    
answered by 13.08.2017 в 12:24