admin配置步骤:
注册自定义的模型类:
代码:
from django.contrib import admin
from .models import Book, Author
# Register your models here.
admin.site.register(Book)
admin.site.register(Author)
模型管理器类(修改):
admin.py:
from django.contrib import admin
from .models import Book, Author
# Register your models here.
# admin.site.register(Book)
# admin.site.register(Author)
class BookManager(admin.ModelAdmin):
# 列表页显示的字段
list_display = ['id', 'title', 'pub', 'price', 'market_price', 'is_active']
# 列表页可以点击进入编辑界面的字段
list_display_links = ['id', 'title']
# 列表页可以直接编辑的字段
list_editable = ['price']
# 列表页右侧增加搜索框
search_fields = ['price']
# 列表页右侧增加过滤器
list_filter = ['is_active']
admin.site.register(Book, BookManager)