我有此代码:
from django.contrib import admin
from test_app.models import Master, Detail
class DetailInline(admin.TabularInline):
model = Detail
class MasterAdmin(admin.ModelAdmin):
inlines = [DetailInline]
admin.register(Master, MasterAdmin)
但是在某种程度上,它不会显示在django管理员索引页面中。
列出了其他应用,它们的admin.py
文件看起来很相似。
此代码有什么问题?
答案 0 :(得分:7)
使用admin.site.register(Master, MasterAdmin)
from django.contrib import admin
from test_app.models import Master, Detail
class DetailInline(admin.TabularInline):
model = Detail
class MasterAdmin(admin.ModelAdmin):
inlines = [DetailInline]
admin.site.register(Master, MasterAdmin)
@register
decorator from django.contrib import admin
from test_app.models import Master, Detail
class DetailInline(admin.TabularInline):
model = Detail
@admin.register(Master)
class MasterAdmin(admin.ModelAdmin):
inlines = [DetailInline]