如何在管理员列表中添加自定义按钮?

Jay*_*eto 6 django-admin

我想要的是在管理列表的页面的每一行中放置一个自定义按钮.
这些按钮将具有与其相关联的功能.
我已经知道"管理员行动",但这不是我想要的,好吗?

谢谢!

Ber*_*ant 21

您可以在ModelAdmin中声明一个函数来为您的按钮生成html,例如

    def button(self, obj):
        return mark_safe('<input type="...">')
    title.short_description = 'Action'
    title.allow_tags = True
Run Code Online (Sandbox Code Playgroud)

然后把它放在你的list_display-tuple中.

class MyAdmin(admin.ModelAdmin)
    list_display=('name', 'button')
Run Code Online (Sandbox Code Playgroud)

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-options