librelist archives

« back to archive

Integrate models into flask extension

Integrate models into flask extension

From:
fouad Chennouf
Date:
2015-03-03 @ 18:28
Hi everybody,

I was trying to understand a concept in flask and specifically in
flask-sqlalchemy. My problem was that I couldn't integrate generic models
in an extension that I was developing. contrary to forms (wtforms) that you
can easily integrate to an extension (pure class inheritance), models
cannot be added to an extension because classes of our model inherit from
an object that must be initialized in the app ( db=sqlalchemy() ).

So couldn't I do something like MyClassModel(GenericClassModel) ? I tried
to look for information in sqlalchemy and it seems to be related to the
Base class of sqlalchemy which is dynamic (an object), so it need to be
created somewhere.

I guess this is related to the fact that the application will use a unique
database, and the representation of this database is created dynamically.
and all classes of our model must be linked to this unique database.

Why can't we imagine a creation of our class models, inheriting from
another class. and class are imported in a the main flask app and then the
creation of the database, or the link between the database and our models
can be easily done. I must have missed some concepts, if someone already
looked into this situation, maybe he can share knowledge with us. Thanks
everybody.

-- 
Fouad CHENNOUF.
Embedded Software and Security Engineer