选择一个有效的选择。 __不是可用的选择之一

时间:2019-04-03 06:50:28

标签: python django django-models django-forms

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}

这工作得很好,但是当我将此选择字段更改为“多个复选框”时,它将引发如下错误:

enter image description here

有人可以在这里解释我在做什么错吗?

这是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}

0 个答案:

没有答案