pythondjangodjango-modelsdjango-admin

Reverse Inlines in Django Admin


I have 2 models as follows. Now I need to inline Model A on Model B's page.

models.py

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

class B(models.Model):
    name = models.CharField(max_length=50)
    a = models.ForeignKey(A)

admin.py

class A_Inline(admin.TabularInline):  
    model = A

class B_Admin(admin.ModelAdmin): 
    inlines = [A_Inline]

is that possible?? If yes please let me know..


Solution

  • No, as A needs to have a ForeignKey to B to be used as an Inline. Otherwise how would the relationship be recorded once you save the inline A?