开发者

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

开发者 https://www.devze.com 2022-12-29 21:49 出处:网络
What I want is to put a custom button in each row of a page of the ad开发者_Go百科min listing. These buttons will have a function associate to it acting over that line.

What I want is to put a custom button in each row of a page of the ad开发者_Go百科min 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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消