[Solved]-Django (admin.e104) must inherit from 'InlineModelAdmin'


My stupid mistake was that I had the inline class name inside quotes.

instead of:

class MyAdmin(admin.ModelAdmin):
    inlines = [MyInlineAdmin]

it was:

class MyAdmin(admin.ModelAdmin):
    inlines = ['MyInlineAdmin']

Total Cost:

  • 2 Hours
  • Some scratches on the laptop screen
  • Less swimming today in the sea


I made a variation of the same mistake.

My inline was:

class MyModelInline(admin.StackedInline):
    model = MyModel

But I referred to the inline by the model name, not the inline name:

class OtherModelAdmin(admin.ModelAdmin):
    inlines = [MyModel]

Whereas it should have been:

class OtherModelAdmin(admin.ModelAdmin):
    inlines = [MyModelInline]

That mistake was generating the following error:

<class 'app_name.admin.OtherModelAdmin'>: (admin.E104) 'app_name.models.models_file.MyModel' must inherit from 'InlineModelAdmin'.


Found the reason.
In actual code, which is not mine originally, names of models are the same as names of files they are placed in. Son at some step of checking Django (or python) detects inheritance of RemoteProductModel from LocalProductModel as error – like inheritance from file, not class-model. And after that it cannot work with it’s fields and of course RemotePurchaseAdmin cannot make import as inline as model if remote product.
It does not warn about inheritance error but raieses admin.E104 for admin.ModelAdmin, that tried to import incorrect model or inline.

Thanks everyone. Hope this will warn other developers from stupid mistakes.


Yes the problem is the model name has changed, I solve this running makemigrations and migrate


It’s obvious once you see it…

enter image description here

Notice the accidental comma outside of the inlines list? That triggers the warning too.

Leave a comment