BB
Size: a a a
BB
DT
PC
DT
BB
DT
DT
DT
DT
PC
CHOICES_GENDER = [('m', 'man'), ('w', 'woman')]forms.py:
class Student(models.Model):
...
gender = models.CharField(max_length=1, choices=CHOICES_GENDER)
class StudentAddForm(forms.ModelForm):template.html:
...
gender = forms.ChoiceField(widget=forms.RadioSelect(attrs={'class': 'radio-control'}),
choices=CHOICES_GENDER, initial='m'),
...
<form action="" method="post" novalidate>Радио-кнопки все равно не появляются, обычный селектор унылый.
{% csrf_token %}
<table>
{{ form.as_table }}
<tr>
<td> </td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
BB
DT
CHOICES_GENDER = [('m', 'man'), ('w', 'woman')]forms.py:
class Student(models.Model):
...
gender = models.CharField(max_length=1, choices=CHOICES_GENDER)
class StudentAddForm(forms.ModelForm):template.html:
...
gender = forms.ChoiceField(widget=forms.RadioSelect(attrs={'class': 'radio-control'}),
choices=CHOICES_GENDER, initial='m'),
...
<form action="" method="post" novalidate>Радио-кнопки все равно не появляются, обычный селектор унылый.
{% csrf_token %}
<table>
{{ form.as_table }}
<tr>
<td> </td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
DT
PC
DT
class StudentAddForm(forms.ModelForm):
class Meta:
model = ...
fields = (
...,
'gender'
...,
)
widgets = {
'gender': widgets.RadioSelect()
}
PC
class StudentAddForm(forms.ModelForm):
class Meta:
model = ...
fields = (
...,
'gender'
...,
)
widgets = {
'gender': widgets.RadioSelect()
}
DT
DT
DT