简而言之,我正在尝试让Django Admin为多个关系呈现内联。可以吗?怎么样?参加以下未经测试的 *插图*;假设它有用,我会去管理门户,选择人,并添加孩子(儿子/女儿)和学生。
模型示例(models.py)
class Person(models.Model):
name = models.CharField(max_length=400)
parent = models.ForeignKey('self',related_name='children')
teacher = models.ForeignKey('self',related_name='students')
Django Admin(admin.py)
class ChildrenInline(admin.TabularInline):
model = Person
fk_name = 'parent'
class StudentsInline(admin.TabularInline):
model = Person
fk_name = 'teacher'
class PersonAdmin(admin.ModelAdmin):
inline = [ChildrenInline,StudentsInline]
model = Person
admin.site.register(Person,PersonAdmin)
如果以上代码在技术上正确,我需要弄清楚发生了什么。
谢谢!