Django Admin上的多对多字段视图 [英] Many-To-Many Fields View on Django Admin
本文介绍了Django Admin上的多对多字段视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我试图在此模型中重新创建一个类似于django用户身份验证系统的字段,为此,我尝试使用多对多字段,但最终却像这样.
Basically I am trying to recreate a fields in this model that is similar to django user authenticate system, for this I try using many-to-many fields but it ended up like this.
我试图拥有一个可以显示存在的字段,并且为我选择的另一个字段类似于django admin,看起来像这样.
I am trying to have another field that can show what exist and another field for I have chosen similar to django admin, which looks like this.
这是我的代码
class Category(models.Model):
name = models.CharField(max_length=128, unique=True)
class BlogPage(models.Model):
category = models.ManyToManyField(Category)
title = models.CharField(max_length=128)
preview = models.TextField(max_length=256)
content = models.TextField()
推荐答案
我相信您想要的是管理模板中使用的 filter_horizontal
小部件.这应该会有所帮助: Django Admin ManyToManyField
I believe what you want is a filter_horizontal
widget used in the Admin template. This should help: Django Admin ManyToManyField
这篇关于Django Admin上的多对多字段视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文