我希望用户能够通过管理界面进行多项选择,并将结果存储为逗号分隔值列表。选择多个或复选框列表会很棒。但是,我不需要这个值列表中的项目来特别引用任何模型......我只想要一个简单明了的项目文本列表,因此我不认为 ManyToManyField 是我的那个'我在找。在 Django 中执行此操作的最快方法是什么?
最佳答案
有一个 django 代码段就是这样做的:multiple choice model field .它说:
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.
关于python - 除了 ManyToMany 之外,是否有允许多种选择的 Django 模型字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2267332/