1

Given three models related by M2M fields:

A <-> B <-> C

models

class A(models.Model):
    name = models.CharField()

class B(models.Model):
    a = ManyToManyField(A)

class C(models.Model):
    b = ManyToManyField(B)

With the following admin I have an Inline between A-B:

admin

class BInline(admin.TabularInline):
    model = B.a.through

class AAdmin(admin.ModelAdmin):
    inlines = [BInline,]

What I need now is to have another inline between A and C. But I don't know how to set the relation among them.

class CInline(admin.TabularInline):
    model = #¿?

class AAdmin(admin.ModelAdmin):
    inlines = [ BInline,
                CInline,
                ]
loar
  • 1,505
  • 1
  • 15
  • 34
  • Why do you want to display all the C's in A, wouldn't it make more sense to display them as an inline in B? – Written Jul 06 '16 at 15:49
  • @Written I would agree with you but this time it has to be like this for the purposes of the application. – loar Jul 06 '16 at 15:52
  • Ahh, I see. Well I recommend checking out this link: http://stackoverflow.com/questions/4999577/django-orm-way-of-going-through-multiple-many-to-many-relationship if you haven't already. Might be along the lines of what you're looking for – Written Jul 06 '16 at 16:11

0 Answers0