[Flask] Registering Flask-SQLAlchemy models from an extension

David Baumgold david at davidbaumgold.com
Sun Feb 11 16:30:21 EST 2018


I’m the maintainer of Flask-Dance, and my extension has to deal with this problem, too. I decided to solve it by providing a mixin class, and directing developers to define their own ORM model by inheriting from that mixin class. Then, the developer must pass the defined ORM model back to a class I defined, that knows how to handle it.

Here’s the relevant documentation for my Flask extension: https://flask-dance.readthedocs.io/en/latest/backends.html#sqlalchemy
And here’s the docs for SQLAlchemy mixins: http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/mixins.html

Does that help?

David Baumgold

On February 11, 2018 at 8:27:42 PM, Gergely Polonkai (gergely at polonkai.eu) wrote:

Hello,

I want to create an extension that, among other things, defines ORM models. Being an extension, this means it is not me who defines the flask_sqlalchemy.SQLAlchemy object, so I canʼt write my model classes like

class MyModel(db.Model):

Is there a recipe for this scenario?

Thanks in advance,
Gergely 
_______________________________________________  
Flask mailing list  
Flask at python.org  
https://mail.python.org/mailman/listinfo/flask  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20180211/0f975470/attachment.html>


More information about the Flask mailing list