Is there a Django ModelField that allows for multiple choices, aside from ManyToMany?

前端 未结 3 2124
后悔当初
后悔当初 2021-02-07 21:36

I\'d like the user to be able to make multiple selections via the admin interface, and store the result as a list of comma-separated values. A select-multiple or a list of check

相关标签:
3条回答
  • 2021-02-07 21:50

    Django-multiselectfield does what you require:

    https://github.com/goinnn/django-multiselectfield

    It's inspired by the snippet that Alexander mentioned.

    0 讨论(0)
  • 2021-02-07 21:53

    This django snippet accomplishes the same with a much smaller footprint.

    http://djangosnippets.org/snippets/23/

    make sure to update those imports since they are pre version 1.0

    0 讨论(0)
  • 2021-02-07 22:10

    There is a django snippet which does just this: multiple choice model field. It says:

    Usually you want to store multiple choices as a manytomany link to another table. Sometimes however it is useful to store them in the model itself. This field implements a model field and an accompanying formfield to store multiple choices as a comma-separated list of values, using the normal CHOICES attribute.

    0 讨论(0)
提交回复
热议问题