【问题标题】:Django CheckboxSelectMultiple with django uni-formDjango CheckboxSelectMultiple 与 django 统一格式
【发布时间】: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 这样被隐式调用的方法。

标签: python django uniform


【解决方案1】:

我解决了我的问题。问题是当我预填充数据时,我传递的是 event.event_types(一个管理器实例)而不是 event.event_types.all()。

【讨论】:

    猜你喜欢
    • 2018-10-18
    • 2013-03-31
    • 2012-04-06
    • 2012-03-19
    • 2014-09-29
    • 2012-08-01
    • 2012-12-03
    • 2013-10-20
    • 2020-12-03
    相关资源
    最近更新 更多