django admin的自定制
from django.contrib import admin # Register your models here. from .models import * from django.utils.safestring import mark_safe class BookConfig(admin.ModelAdmin): def deletes(self): return mark_safe("<a href=''>删除</a>") # 添加列,自定义的方法 list_display = ["title","price","publishDate",'publish',deletes]
# 添加跳转,跳转到admin后台对应的表中 list_display_links = ["price"]
# 页面右侧添加过滤条件 list_filter=["price","title","authors","publish"]
# 添加可编辑的对象,可以在页面直接更改数据 list_editable=["title",] # 添加搜索框,以及搜索的对象 search_fields=["title","price"] # 自定义批量初始化 def patch_init(self,request,queryset): queryset.update(price=100)
# 下拉导航栏添加选项
patch_init.short_description = "批量初始化"
# 将定义的初始化操作执行 actions = [patch_init,]
# 更改admin的默认模版 #change_list_template="list.html" fields = ('title',) # 将定义好的class添加到对应的表中 admin.site.register(Book,BookConfig) admin.site.register(Publish) admin.site.register(Author) admin.site.register(AuthorDetail)