[Solved]-DJANGO: How to list_display a reverse foreign key attribute?


Django admin is really flexible, you can simply add a helper method for it.

class PersonAdmin(admin.ModelAdmin):
    list_display = ('name', 'books')

    def books(self, obj):
        return ",".join([k.name for k in obj.book_set.all()])


Add an inlinemodel admin

class BookInline(admin.TabularInline):
    model = book

class PersonAdmin(admin.ModelAdmin):
    inlines = [BookInline, ]

That should cover it.

Leave a comment