Flask Admin使用自定义按钮扩展“带有选择"下拉菜单

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))