美文网首页
django里的 admin 常用配置

django里的 admin 常用配置

作者: dongshangtong | 来源:发表于2019-05-16 13:57 被阅读0次

常用的配置的字段


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)

相关文章

网友评论

      本文标题:django里的 admin 常用配置

      本文链接:https://www.haomeiwen.com/subject/zmciaqtx.html