【发布时间】:2014-11-03 18:26:28
【问题描述】:
我正在尝试显示一个单选组,而不是默认下拉列表。我的表单如下所示:
class ConditionForm(forms.ModelForm):
state = forms.ChoiceField(choices=STATE_TYPES, widget=forms.RadioSelect())
class Meta:
model = Customer
fields = ('state',)
我也试过这个: 类ConditionForm(forms.ModelForm):
class Meta:
model = Customer
fields = ('state',)
widgets = {
'state': forms.RadioSelect(),
}
我的模型如下所示:
STATE_TYPES = (
(0, 'Type 2'),
(1, 'Type 1'),
)
class Customer(models.Model):
state = models.IntegerField(choices=STATE_TYPES, default=0, null=True)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
我的模板看起来像:
{{ form.state }}
这会输出一个下拉菜单,而不是 4 个单选按钮。
我做错了什么?
【问题讨论】:
标签: django django-models django-forms