models.py
supplier_type_choices = (('transporter', 'Transporter'), ('broker', 'Broker'), ('fleet Owner', 'Fleet Owner'))
class Supplier(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
trucktypes = models.ManyToManyField(Subject, related_name='interested_suppliers')
supplier_type = models.CharField(choices=supplier_type_choices, default=0, max_length=100)
supplier_name = models.CharField(max_length=100, default=0)
forms.py 版本1
class SupplierTruckForm(forms.ModelForm):
supplier_type = forms.ChoiceField(choices=supplier_type_choices)
class Meta:
model = Supplier
fields = (
'trucktypes', 'supplier_address', 'supplier_company_name', 'supplier_email', 'supplier_gst', 'supplier_name',
'supplier_origin_city', 'supplier_pan', 'supplier_service','supplier_type')
widgets = {'trucktypes': forms.CheckboxSelectMultiple,'supplier_type':forms.CheckboxSelectMultiple}
这工作得很好,但是当我将此选择字段更改为“多个复选框”时,它将引发如下错误:
有人可以在这里解释我在做什么错吗?
这是MultipleCheckBoxes的代码:
class SupplierTruckForm(forms.ModelForm):
supplier_type = forms.CheckboxSelectMultiple(choices=supplier_type_choices)
class Meta:
model = Supplier
fields = (
'trucktypes', 'supplier_address', 'supplier_company_name', 'supplier_email', 'supplier_gst', 'supplier_name',
'supplier_origin_city', 'supplier_pan', 'supplier_service','supplier_type')
widgets = {'trucktypes': forms.CheckboxSelectMultiple,'supplier_type':forms.CheckboxSelectMultiple}