在django中使用选择的正确方法

时间:2017-06-11 21:50:58

标签: django

我的选择如下,但我得到一个错误说明 选项必须是包含实际值和可读名称的可迭代

  my model.py


  class mymodel(models.Model):
         MY_CHOICES =(
                     ('corperation1','corperation'),
                     ('Liablility2','Liablility'),
                     )
      Company_type = 
      MultiSelectField(choices=MY_CHOICES,max_choices=1,max_length=2)

1 个答案:

答案 0 :(得分:0)

class mymodel(models.Model):
     company_type = models.CharField(max_length)

class myform(forms.ModelForm):
     company_type = forms.MultipleChoiceField(choices = (('corperation1','corperation'),('Liablility2','Liablility')), widget = forms.MultiSelect())