sqlalchemy - Add table creation task to Flask-Admin model creation -


i'm still learning flask-admin. have field called table_name part of department model. when create new instance, value of table_name becomes row in department table. that's flask-admin designed do. want use form data i.e. value of table_name create table sqlalchemy. know how create table dynamically sqlalchemy. i'm wondering how incorporate flask-admin me. example: if type 'my_table' table_name field in flask admin form, new table called 'my_table' created in schema. how need this? thanks.

you can override modelview's on_model_change , on_model_delete methods, called flask-admin right before commiting changes:

class tableconfig(modelview):     def on_model_change(self, form, model, is_created):         if is_created:             sqlalchemy_create_table(model)      def on_model_delete(self, model):         sqlalchemy_drop)table(model) 

where sqlalchemy_create_table , sqlalchemy_drop_table custom methods create tables, using information in model object passed - in case, table_name property or others.

i implemented exact functionality using flask-admin on live project.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -