Im using the built-in view of flask admin. As you can see in the picture below:
我尝试的很简单:我只想使用自定义按钮扩展下拉菜单。此按钮应对所有选定的项目执行某些操作。
Flask 是否有内置功能,我可以简单地添加操作按钮?
Use the @action装饰师。下面是简单的示例,文本“重新计算费用”出现在下拉菜单中。
class TransactionView(AdminView):
from flask_admin.actions import action
@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:
# Do some work with the id, e.g. call a service method
transaction_service.recalculate_transaction(_id)
count += 1
flash("{0} transaction (s) charges recalculated".format(count))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)