使用单选按钮渲染ChoiceField

时间:2013-10-13 15:45:52

标签: django django-forms

我从模型中构建了这个表单。

class Configure_template(forms.Form):
    subject_type = forms.ChoiceField(choices=Subject_type.objects.all())

我想使用单选按钮渲染它,但我在html中遇到问题,

感谢您的任何建议。

2 个答案:

答案 0 :(得分:6)

在表单字段中使用RadioSelect widget

subject_type = forms.ChoiceField(choices=Subject_type.objects.all(),
    widget=forms.RadioSelect)

答案 1 :(得分:3)

如果要显示带有数据库使用选项的单选按钮,则无法使用选择字段。

您必须使用ModelChoiceField

subject_type = forms.ModelChoiceField(widget=forms.RadioSelect, queryset=Subject_type.objects.all(), label='')
相关问题