【发布时间】:2011-09-24 14:35:38
【问题描述】:
我的 django 项目中有一个表单,其中 ModelMultipleChoiceField 呈现为 CheckboxSelectMultiple 小部件:
class EventCreateForm(forms.Form):
...
event_types = forms.ModelMultipleChoiceField(EventType.objects.all(), widget=forms.CheckboxSelectMultiple())
...
我正在使用 django uni-form 将此表单呈现到页面:
@property
def helper(self):
helper = FormHelper()
submit = Submit('submit', 'Submit')
helper.add_input(submit)
helper.form_action = ''
helper.form_method = 'POST'
return helper
但是,当 django uni-form 尝试渲染该字段时,我收到以下错误:
渲染时捕获 TypeError:'ManyRelatedManager' 对象不是 可迭代
我知道这个错误的常见问题是forgetting to call .all() on the manager,但是这是由 django uni-form 调用的。这是 django uni-form 的问题还是我做错了什么?
【问题讨论】:
-
这可能是模型内部的问题。尝试查看像 unicode 这样被隐式调用的方法。