有没有一个Django ModelField允许多个选择,除了ManyToMany? [英] Is there a Django ModelField that allows for multiple choices, aside from ManyToMany?

查看:68
本文介绍了有没有一个Django ModelField允许多个选择,除了ManyToMany?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户能够通过管理界面进行多个选择,并将结果存储为逗号分隔值的列表。选择复选框或复选框列表将是很棒的。然而,我不需要这个值列表中的项目来引用任何模型...我只想要一个文本列表的项目,简单和简单,因此我不认为ManyToManyField是我的一个' m寻找。在Django中最快捷的方法是什么?

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 checkboxes would be great. However, I don't need the items in this list of values to refer to any models in particular... I just want a text list of items, plain and simple, hence I don't think the ManyToManyField is the one I'm looking for. What's the quickest way to do this in Django?

推荐答案

有一个django代码片段,它只是这样做:多选模型字段。它说:

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


通常你想存储多个
选项作为另一个表的
的manytomany链接。有时候,它是
有用的存储在模型
本身。该字段实现一个模型
字段和一个附带的formfield到
存储多个选项作为
逗号分隔的值列表,使用
正常的CHOICES属性。

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.

这篇关于有没有一个Django ModelField允许多个选择,除了ManyToMany?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆