Django CheckboxSelectMultiple 与 django uni-form
我的 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 尝试呈现该字段时,我收到以下错误:
渲染时捕获类型错误:“ManyRelatedManager”对象不是 可迭代
问题是 忘记在管理器上调用 .all() ,但是这是由 django uni-form 调用的。这是 django uni-form 的问题还是我做错了什么?
I have a form in my django project with a ModelMultipleChoiceField rendered as a CheckboxSelectMultiple widget:
class EventCreateForm(forms.Form):
...
event_types = forms.ModelMultipleChoiceField(EventType.objects.all(), widget=forms.CheckboxSelectMultiple())
...
I'm using django uni-form to render this form to the page:
@property
def helper(self):
helper = FormHelper()
submit = Submit('submit', 'Submit')
helper.add_input(submit)
helper.form_action = ''
helper.form_method = 'POST'
return helper
However, when django uni-form tries to render the field I get the following error:
Caught TypeError while rendering: 'ManyRelatedManager' object is not
iterable
I know the usual problem with this error is forgetting to call .all() on the manager, however this is being called by django uni-form. Is this a problem with django uni-form or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了我的问题。问题是当我预填充数据时,我传递的是 event.event_types (管理器实例)而不是 event.event_types.all()。
I solved my issue. The problem was when I was prepopulating the data, I was passing event.event_types (a manager instance) rather than event.event_types.all().