开发者

Django CheckboxSelectMultiple with django uni-form

开发者 https://www.devze.com 2023-04-08 16:41 出处:网络
I have a form in my django project with a ModelMultipleChoiceField rendered as a CheckboxSelectMultiple widget:

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 t开发者_StackOverflowhis 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?


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().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号