Вопрос

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