Challenge 2: Add an Inline — Possible Solution ==================================================================== # catalog/admin.py from django.contrib import admin from .models import Author, Book, Publisher class BookInline(admin.TabularInline): model = Book extra = 1 @admin.register(Author) class AuthorAdmin(admin.ModelAdmin): list_display = ["name"] inlines = [BookInline] @admin.register(Publisher) class PublisherAdmin(admin.ModelAdmin): list_display = ["name"] inlines = [BookInline] WHY THIS WORKS -------------- - BookInline is defined once and reused for BOTH AuthorAdmin and PublisherAdmin — an inline just needs to know which model to edit (Book) and how many empty "add new" rows to show (extra = 1); Django figures out which foreign key on Book to use for each parent based on which admin page it's attached to (Book.author for AuthorAdmin, Book.publisher for PublisherAdmin). - Because Book has TWO ForeignKeys (author and publisher, from Chapter 6's challenge), this same BookInline class works correctly on both parent admin pages without needing a separate inline class per relationship — Django resolves which FK to use from the inline's context automatically as long as there's only one ForeignKey from Book to whichever model the inline is attached to. - Editing a publisher's books directly from the publisher's own admin page (rather than navigating to the separate Book list and filtering) is exactly the convenience TabularInline exists for — related data that's naturally viewed and edited together, in one place.