python - 除了 ManyToMany 之外,是否有允许多种选择的 Django 模型字段?

标签 python django forms

我希望用户能够通过管理界面进行多项选择,并将结果存储为逗号分隔值列表。选择多个或复选框列表会很棒。但是,我不需要这个值列表中的项目来特别引用任何模型......我只想要一个简单明了的项目文本列表,因此我不认为 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/

相关文章:

ruby-on-rails - PostgreSQL 数组中的值以 Rails 形式重复

python - 如何从 python 脚本中控制 Windows shell 窗口的大小?

javascript - Django Ajax 请求与我的模板中返回的数据有关

html - 使用按钮提交表单

python - 在 Python 3.6 上安装 MySqlDB

python - Django,在模板中创建变量并赋值

html - 样式化具有两列的表单

python - Access 和 pyodbc 的 INSERT 语句中的语法错误

python:使用引用图像和来自相机的当前图像查找相机偏移角度

python - 在 SQLAlchemy 中按小时分组?