I'm using flask-admin's ModelView class along with an SQLalchemy. I want to check for a particular condition inside the on_model_change() function and cancel the update to the Model if the condition is met. How do I do it?

I'm able to get rid of the change when a new model is created by doing this (though not my favourite routine):

if is_created is True:
    if model.some_condition is True:
        self.delete_model(model)

However, I don't see a way of cancelling update when an existing entry is changed.

I also checked return False. That didn't work.

有帮助吗?

解决方案

You can override on_model_change and throw exception from there. If app is ran in debug mode, it will show werkzeug debugger and if app is running in release mode, it'll show exception text in a tooltip.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top