0

I need to create django form with checkbox fields. Number of fields and value of "checked" attribute are dynamic.

I created form:

form = DynamicForm()
for field in all_fields:
    if field in checked_field:
        form.fields[field.id]=forms.BooleanField(label=field.name, initial=True)
    else:
        form.fields[field.id]=forms.BooleanField(label=field.name, initial=False)
return form

,but this form has different value of "name" attribute for each field (name=field.id). How to set the same name for every field?

4

1 回答 1

1

You don't do with multiple BooleanFields. You do it with a single MultipleChoiceField, which is output as a series of checkboxes with the same name.

于 2013-08-01T08:04:39.213 回答