如何在管理列表中添加自定义按钮? [英] How do I add a custom button to the admin listing?

查看:124
本文介绍了如何在管理列表中添加自定义按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是在管理列表页面的每一行中放置一个自定义按钮。

这些按钮将具有与该行对应的功能。

我已经知道管理员操作,但这不是我想要的,好吗?

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?

谢谢!

推荐答案

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

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

然后将其放在您的 list_display -tuple。

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

这篇关于如何在管理列表中添加自定义按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆