Python 在默认Django表单中添加单选按钮:
我想我写的代码是正确的。但是这个性别单选按钮并没有出现在我的表格中 这是我的模型视图Python 在默认Django表单中添加单选按钮:,python,django,forms,button,radio,Python,Django,Forms,Button,Radio,我想我写的代码是正确的。但是这个性别单选按钮并没有出现在我的表格中 这是我的模型视图 class Charter(models.Model): CHOICES = [('M', 'Male'), ('F', 'Female'), ('O', 'Others')] Gender = forms.ChoiceField(label='Gender', widget= forms.RadioSelect(choices=CHOICES))
class Charter(models.Model):
CHOICES = [('M', 'Male'), ('F', 'Female'), ('O', 'Others')]
Gender = forms.ChoiceField(label='Gender', widget=
forms.RadioSelect(choices=CHOICES))
created_at = models.DateField()
First_name = models.CharField(max_length=200, unique=True)
Last_name = models.CharField(max_length=200, unique=True)
address = models.CharField(max_length=200, unique=True)
Cell_no = models.CharField(max_length=200, unique=True)
created_at = models.DateField()
这是我的表格
从django.forms导入ModelForm
从。模型导入*
class CharterForm(ModelForm):
class Meta:
model= Charter
fields = '__all__'
widgets = {
'Gender': forms.RadioSelect()
}
查看此类似链接: 或 有关更多信息,请参阅
CHOICES = (
('M', 'Male'),
('F', 'Female'),
('O', 'Others'),
)