admin有自己的默认显示,要自定义显示的样式,一般需要自己定义一个类,在自己定义的类里进行相应的设置,然后,把自己的类交给装饰器
交给装饰器的方法有两种:
1.@admin.register(Publisher)
2.admin.site.register(Publisher, PublisherAdmin)
两种方式选择一种就可以了
官方网址:https://docs.djangoproject.com/en/1.9/ref/contrib/admin
例子:
@admin.register(Publisher)
class PublisherAdmin(admin.ModelAdmin):
list_display = ('name', 'country', 'state_province', 'city',)
search_fields = ('name', 'city',)
list_filter = ('state_province',)
ordering = ('-id',)
# fields = ('name', 'address',)
# exclude = ('name', 'address',)
fieldsets = (
(None, {
'fields': ('name', 'address', )
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('city', 'state_province', 'country', 'website'),
}),
)
# admin.site.register(Publisher, PublisherAdmin)
看实际的展示效果