这就是我的班级的样子。
chart: {
events: {
load: function () {
this.drawnItems = []
},
click: function (e) {
const { x, y } = e
const text = this.renderer.text('custom text', x, y).add()
text.point = translate(x, y, this)
this.drawnItems.push(text)
},
redraw: function () {
this.drawnItems.forEach(item => {
const { x, y } = item.point
item.attr(translate(x, y, this, true))
})
}
}
},
在哪个州,地区,群集也是类。我试图建立一个学校网络,分为3个级别,即州,地区,集群。 我假设当我从django admin添加学校时,我认为如果我在选择区域时选择状态和过滤器集群可能会过滤区域,这样就很容易了。但它似乎没有用。虽然在群集下拉列表中添加学校后选择了特定的州和地区,但所有州和地区的所有群集都将来临。
是否有解决方案或截至目前我们在django中没有这样的选项?
答案 0 :(得分:1)
从django-smart-selects包中尝试 ChainedForeignKey ,它就像魔术一样。
pip install django-smart-selects
项目settings.py
INSTALLED_APPS=[
. . . . .
. . . . .
'smart_selects',
. . . . .
]
项目urls.py
urlpatterns = [
. . . . .
url(r'^admin/', include(admin.site.urls)),
url(r'^chaining/', include('smart_selects.urls')),
. . . . .
]
请参阅installation of django-smart-selects
from smart_selects.db_fields import *
class State(models.Model):
stateName = models.CharField(max_length=500)
. . . .
class Region(models.Model):
state = models.ForeignKey(State, on_delete=models.CASCADE)
regionName = models.CharField(max_length=500)
. . . . .
. . . . .
class Cluster(models.Model):
state = models.ForeignKey(State, on_delete=models.CASCADE)
region = ChainedForeignKey(Region,chained_field="state",chained_model_field="state", show_all=False, auto_choose=True, sort=False, on_delete=models.CASCADE)
clusterName = models.CharField(max_length=500)
. . . . .
. . . . .
class school(models.Model):
state = models.ForeignKey(State, on_delete=models.CASCADE)
region = ChainedForeignKey(Region, chained_field="state",chained_model_field="state", show_all=False, auto_choose=True, sort=False, on_delete=models.CASCADE)
cluster = ChainedForeignKey(Cluster, chained_field="region",chained_model_field="region", show_all=False, auto_choose=True, sort=False, on_delete=models.CASCADE)
schoolName = models.CharField(max_length=500)
. . . .
. . . .
试试这个,它在admin area
中运行良好。