Django : Inline editing of related model using inlineformset -
i'm still stuck inline tree-like-eiditing of related models on same page. i've got 3 models, a, b , c.
class class b fb = foreignkey(a) class c fc = foreignkey(b)
in admin.py i'm doing like
admina inlines = [inlineb] adminb inlines = [inlinec]
i want when edit/add model a, should able add modelb inline, , add model b's related model c entries. trying out inlineformsets, can't find out how use them purpose. moreover, found this old discussion on same problem. again, since i'm new django, don't know how make work.
its bit odd answering own question, hey nobody else stepped up. , bernd pointing me in right direction. solution required making intermediary model. class bc in case.
class a(models.model): = models.integerfield() class b(models.model): fb = models.foreignkey(a) b = models.integerfield() class c(models.model): fc = models.foreignkey(b) c = models.integerfield() class bc(models.model): fc = models.foreignkey(a) fb = models.foreignkey(b)
and instead of having inlineb in admin of model a, use inline of bc. full admin.py looks like.
class inlinec(admin.tabularinline): model = c = 1 class bcinline(admin.tabularinline): model = bc = 1 class admina(admin.modeladmin): fieldsets = [ (none, { 'fields': ('a',) }), ] inlines = [bcinline] class adminb(admin.modeladmin): fieldsets = [ (none, { 'fields': ('b',) }), ] inlines = [inlinec]
and voila, button popus create full object of b, in add page of model a.
Comments
Post a Comment