我有一组类似的模型:
class Parent(models.Model):
name = models.CharField()
class Child(models.Model):
name = models.CharField()
parent = models.ForeignKey(Parent)
class GrandChild(models.Model):
name = models.CharField()
parent = models.ForeignKey(Child)
在Django管理员中,我可以将Child
设置为admin.TabularInline
的{{1}}。我想添加一个链接,该链接会弹出一个窗口,允许我添加GrandChild
此刻,我可以通过在Parent
的{{1}}中包括以下内容来创建现有GrandChild
记录的列表
admin.TabularInline
我想添加一个弹出Django管理员弹出窗口的内容(就像对ForeignKey关系所做的那样),以添加链接到关联的ChildInline
的{{1}}。
我不知道如何设置ID为def grand_children(self, obj):
text = ''
for grandchild in obj.grandchild_set.filter(completed=False):
text += grandchild.name + '<br />'
return mark_safe(text)
grand_children.short_description = 'Grand Children'
的窗口。你能帮忙吗?