1

I want to set different id for each radio choice.

My Model:-

class Preference(models.Model):
      BOARD_CHOICES = [('CB', 'CBSE'), ('IC', 'ICSE'), ('SB', 'State Board'),
                 ('IB', 'International Board')]
      Board = models.CharField(max_length=30, choices=BOARD_CHOICES, default='CBSE', blank=False)

My Form:-

class PreferenceForm(forms.ModelForm):
    class Meta:
       model = Preference
       fields = ['Board']
       widgets = {
           'Board': forms.RadioSelect(),
           }

i.e for the radio button with label 'CBSE' I want to set id to say 'choice_1' and so on.

All help/suggestion would be appreciated.

1 Answers1

0

How about this solution ?

I wrapped-up with something like this:

<label>{{ form.origem.label }}</label>
{% for choice in form.origem %}
    <div class="">
        {{ choice.tag }}
        <label class="radio-style-1-label" for="id_{{form.origem.name}}_{{forloop.counter0}}">{{ choice.choice_label }}</label>
    </div>
{% endfor %}
diogosimao
  • 163
  • 2
  • 9