In brief, i’m trying to get Django Admin to render inlines for more than one relationship to self. Can it be done? How? Take the following untested *illustration*; Assuming it worked i’d go to admin portal, select person, and add children (sons/daughters) and students.
Model Example (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)
If the above code it technically correct i’ll need to figure out what’s going on.
Thanks!
You have a typo !
inline =instead of pluralinlines =like in the docs.I tested, it works with
inlines =🙂Also, kudos for posting the right code to reproduce !