【发布时间】:2011-07-13 23:08:22
【问题描述】:
我正在尝试在从查询集加载的 ModelChoiceField 中创建一个表单,我想向 ModelChoiceField 添加一些自定义值以进行扩展,我使用了选择字段,如下所示,但在更新表单时,出现以下错误
表单错误: 选择一个有效的选项。该选择不是可用的选择之一。
代码:
self.fields['lead'] = forms.ModelChoiceField(queryset = Pepole.objects.filter(poc__in = ('lead','sr.lead')))
self.fields['lead2'] = forms.ModelChoiceField(queryset = Pepole.objects.filter(role__in = ('lead','sr.lead')))
choice_field = self.fields['lead']
choice_field.choices = list(choice_field.choices) + [('None', 'None')]
choice_field = self.fields['lead2']
choice_field.choices = list(choice_field.choices) + [('None', 'None')]
我在这里做错了吗?
【问题讨论】:
标签: django django-forms