Search code examples
pythonflaskflask-admin

Could someone please show me where I can find Flask-Admin callbacks?


I am attempting to combine Flask-Admin and a Flask S3 Tool Suite written by someone to store images to Amazon S3 simple storage. The tool I am trying to specifically use is the S3Saver functionality and in the article link the user goes on to say that to incorporate this tool, I would ideally use it on a flask-admin callback.

However, I cannot find a list of Flask-Admin callbacks anywhere. I have done my homework and I have literally checked the entire docs and source code for these callbacks Flask-Admin documentation .

In flask_admin.contrib.sqla I found some methods that kind of resembled a callback but its not what I am looking for. I imagine that it is something close to Rails's before_action and after_action. Can someone please point me in the right direction?

By the way this is the actual quote from the article

If you wanted to handle deleting files in the admin as well, you could (for example) use s3-saver, and hook it in to one of the Flask-Admin event callbacks

What callbacks are those?


Solution

  • Flask-Admin Callback Functions (as far as I know)

    after_model_change(form, model, is_created)
    #Called from create_model after successful database commit.
    
    after_model_delete(model)
    #Called from delete_model after successful database commit (if it has any meaning for a store backend).
    
    
    on_form_prefill(form,id) 
    # Called from edit_view, if the current action is rendering the form rather than receiving client side input, after default pre-filling has been performed.
    
    on_model_change(form,model,is_created) 
    #Called from create_model and update_model in the same transaction (if it has any meaning for a store backend).
    
    on_model_delete(model) 
    # Called from delete_model in the same transaction (if it has any meaning for a store backend).
    

    More info at http://flask-admin.readthedocs.org/en/latest/api/mod_model/ (search for "Called from")