我有以下模型:
class Technology(models.Model):
short_name = models.CharField(max_length=30, null=True, unique=True)
name = models.CharField(max_length=100, unique=True)
provider = models.CharField(max_length=100)
def __str__(self):
return self.name
class Entity(models.Model):
short_name = models.CharField(max_length=30, null=True)
name = models.CharField(max_length=100)
description = models.CharField(max_length=500, null=True)
is_storage = models.CharField(max_length=1)
is_presentation = models.CharField(max_length=1)
technology = models.ForeignKey(Technology, on_delete=models.CASCADE)
class Meta:
unique_together = (('short_name', 'technology'),)
def __str__(self):
return '{0} - {1}'.format(self.technology.name, self.name)
class Node(models.Model):
name = models.CharField(max_length=255, unique=True)
display_name = models.CharField(max_length=100, null=True)
description = models.CharField(max_length=500, null=True)
entity = models.ForeignKey(Entity, on_delete=models.CASCADE)
class Meta:
unique_together = (('name', 'entity'),)
def __str__(self):
return self.name
我想为Node模型构建以下形式:
问题是第一个下拉菜单-如何实现?我试过了 : https://simpleisbetterthancomplex.com/tutorial/2018/01/29/how-to-implement-dependent-or-chained-dropdown-list-with-django.html 但是技术下拉列表没有出现在表单页面上,并且在大多数示例中,所有表单字段都来自模型以进行插入/更新。 请同时提供模板定义。 非常感谢, 帕维尔