我想创建一个表单,在该模型从Queryset加载ModelChoiceField,我想添加一些自定义值到ModelChoiceField为扩展我已经使用选择字段,如下所示,但在更新窗体时,得到低于错误形式ModelChoiceField查询集+额外的选择字段Django形式
表单错误: 选择一个有效的选择。该选择不是可用选择之一。
代码:
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')]
我做错任何事情错在这里?
没有,加入empty_label =“无”,也何尝不是working.here我的问题太从查询集扩展的选择,选择选项后 – sush 2011-03-12 09:40:54