Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top