[Fixed]-Inline in Django admin: has no ForeignKey

23👍

The inline model should be having a ForeignKey to the parent model. To get Photo as inline in Author your models code is fine. But your admin code should be as follows:

class PhotoInline(admin.StackedInline):
    model = Photo

class AuthorAdmin(admin.ModelAdmin):
    list_display = ('display_name','user_email')
    inlines = [PhotoInline]

Read more info here.

👤arulmr

4👍

That’s because Author doesn’t have a foreign key to photo. I think you need to switch the model for the inline like this:

class PhotoInline(admin.StackedInline):
    model = Photo

class AuthorAdmin(admin.ModelAdmin):
    list_display = ('display_name','user_email')
    inlines = [PhotoInline]
👤bnjmn

0👍

Maybe you need to install django-nested-admin library, and later try with NestedStackedInline.
django-nested-admin

Leave a comment