As said, how would I render a Choice field into a template with each radio choice rendering separately for which I can have a control over every individual choices.
This is what had been done so far.
models.py
First = 0
Business = 1
Economy = 2
CLASS = (
(First, 'First'),
(Business, 'Business'),
(Economy, 'Economy'),
)
class Lead(models.Model):
....
class_type = models.CharField(null=True, blank=True, choices = CLASS)
form.py
class Lead_form(ModelForm):
class Meta:
model = Lead
fields = ['class_type']
widgets = {
...
'class_type' : forms.RadioSelect(
attrs={'class': 'form-control', 'name': 'ClasstypeRadios' }),
...
}
html
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label">Class Type</label>
<div class="col-sm-4">
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="ClasstypeRadios" id="ClasstypeRadios1" value="0" checked=""> First<i class="input-helper"></i>
</label>
</div>
</div>
<div class="col-sm-5">
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="ClasstypeRadios" id="ClasstypeRadios2" value="1"> Business <i class="input-helper"></i>
</label>
</div>
</div>
</div>
</div>
....
This is so far I've tried but there is still something missing. As can be seen, the radio buttons are dealing differently but not as a "li" tag which is the default way to render by django into templates via {{ form.class_type }} but rather, I would like to render them individually to have a control over every one of the choices. Reference: https://stackoverflow.com/a/6768635/12280790
What am I missing.