[Flask] Registering Flask-SQLAlchemy models from an extension

Gergely Polonkai gergely at polonkai.eu
Mon Feb 12 00:09:24 EST 2018

Thatʼs exactly how Flask-Login works (that extension is not even aware of
the database).

I considered this path, too, and will probably go with that, as it lets the
developer choose how to persist data, and wonʼt bind them to one specific

However, Iʼm still interested in a solution to the original problem, so if
anyone knows it, donʼt hesitate to reply :)


On Sun, Feb 11, 2018, 22:30 David Baumgold <david at davidbaumgold.com> wrote:

> 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/20180212/62df94e5/attachment.html>

More information about the Flask mailing list