Junior — Middle
Can you explain the purpose and operation of inline in Django admin?
sobes.tech AI
Answer from AI
In Django admin, inline is used to display and edit related models directly on the parent model's page. This is convenient when you have a one-to-many or many-to-many relationship, and you want to manage related objects in a single interface.
Example:
from django.contrib import admin
from .models import Author, Book
class BookInline(admin.TabularInline):
model = Book
extra = 1 # number of empty forms to add new books
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline]
In this example, on the author editing page, you can immediately add and edit books related to this author.