django里的 admin 常用配置
2019-05-16 本文已影响0人
dongshangtong
常用的配置的字段
class BookConfig(admin.ModelAdmin):
def deletes(self):
return mark_safe("<a href=''>删除</a>")
# 常用配置字段
list_display = ["title", "price", "publishDate", 'publish', deletes]
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, ]
# change_list_template="list.html"
fields = ('title',)
admin.site.register(Book, BookConfig)