Flask Admin使用自定义按钮扩展“带有选择"下拉菜单 [英] Flask Admin extend "with select"-dropdown menu with custom button

查看:86
本文介绍了Flask Admin使用自定义按钮扩展“带有选择"下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用flask admin的内置视图.如您在下面的图片中看到的:

Im using the built-in view of flask admin. As you can see in the picture below:

我想尝试的方法很简单:我只想使用自定义按钮扩展下拉菜单.此按钮应对所有选定项目执行一些操作.烧瓶是否有内置功能,我可以在其中简单地添加一个动作按钮?

What Im trying is simple: I just want to extend the dropdown menu with a custom button. This button should perfome some action on all selected items. Is there are built-in function of flask where i can simple add an action button?

推荐答案

使用 @action 装饰器.在下面的简单示例中,下拉菜单中显示的是重新计算费用"文本.

Use the @action decorator. Simple example below, the text "Recalculate Charges" is what appears in the drop-down menu.

class TransactionView(AdminView):

@action('recalculate', 'Recalculate Charges', 'Are you sure you want to recalculate selected transactions(s)?')
def action_recalculate(self, ids):
    count = 0
    for _id in ids:
        transaction_service.recalculate_transaction(_id)
        count += 1
    flash("{0} transaction (s) charges recalculated".format(count))

这篇关于Flask Admin使用自定义按钮扩展“带有选择"下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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