Django Multiple Choice Field / Checkbox Select Multiple

前端 未结 6 1158
清酒与你
清酒与你 2020-11-29 18:09

I have a Django application and want to display multiple choice checkboxes in a user\'s profile. They will then be able to select multiple items.

This is a simplifi

6条回答
  •  攒了一身酷
    2020-11-29 19:14

    The models.CharField is a CharField representation of one of the choices. What you want is a set of choices. This doesn't seem to be implemented in django (yet).

    You could use a many to many field for it, but that has the disadvantage that the choices have to be put in a database. If you want to use hard coded choices, this is probably not what you want.

    There is a django snippet at http://djangosnippets.org/snippets/1200/ that does seem to solve your problem, by implementing a ModelField MultipleChoiceField.

提交回复
热议问题