How do I add a custom button to the admin listing?

2019-04-08 04:02发布

What I want is to put a custom button in each row of a page of the admin listing.
These buttons will have a function associate to it acting over that line.
I've already knew the "admin actions", but it's not what I want, ok?

Thank you!

1条回答
等我变得足够好
2楼-- · 2019-04-08 04:38

You can declare in your ModelAdmin a function to generate the html for your button, e.g.

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

And then put it in your in your list_display-tuple.

class MyAdmin(admin.ModelAdmin)
    list_display=('name', 'button')

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

查看更多
登录 后发表回答