让我举个例子:
admin.py
from django.contrib import admin
from .models import Author, Book
class BookInline(admin.TabularInline):
model = Book
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
list_display = ('last_name', 'first_name', 'date_of_birth', 'date_of_death')
fields = ['first_name', 'last_name', ('date_of_birth', 'date_of_death')]
inlines = [BookInline]
此配置生成以下布局:
问题是,这位作者只写了一本书(即Book 009
),但我列出了四本书(即Book 009
和三本“空书”)。为什么?如何禁用此功能(或错误,无论如何)?