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?
Use the @action
decorator. Simple example below, the text "Recalculate Charges" is what appears in the drop-down menu.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With