[英]How to show choices fields in django admin?
I have a model with a lot of fields, Some fields are Char type with choices https://docs.djangoproject.com/en/dev/ref/models/fields/#choices我有一个 model 有很多字段,有些字段是 Char 类型,有选择https://docs.djangoproject.com/en/dev/ref/models/fields/#choices
These fields don't display in the admin panel这些字段不会显示在管理面板中
list_display I generate like this list_display 我这样生成
list_display = [field.name for field in Event._meta.get_fields()]
How to change the generation of the list, so that fields with type choices are shown?如何更改列表的生成,以便显示具有类型选择的字段?
Thanks in advance提前致谢
You can create a list choices on you model like this:您可以像这样在 model 上创建一个列表选项:
On the top of your models.py declare this:在您的 models.py 顶部声明:
SAMPLE_LIST = ((1, 'LIST 1'),
(2, 'LIST 2'),
(3, 'LIST 3'),
(4, 'LIST 4'))
Then on your model class, you can use it like this:然后在您的 model class 上,您可以像这样使用它:
class tblWhatever(models.Model):
LIST_FIELD = MultiSelectField(choices=SAMPLE_LIST ,blank=True,null=True)
def __str__(self):
return str(self.LIST_FIELD)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.