-
-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating flask-sqlalchemy models that are reusable #269
Comments
A gross way I can think of doing this is to wrap the model definitions in a function to form some kind of factory, where you pass in the SQLAlchemy instance you're using, which then creates your model classes using the given SQLAlchemy instance's Model and Query. |
After a bit more research, these seem like they could be useful: "How to use flask-sqlalchemy with existing sqlalchemy model?" - http://stackoverflow.com/questions/19119725/how-to-use-flask-sqlalchemy-with-existing-sqlalchemy-model "Document how to use plain SQLAlchemy models with the Flask-SQLAlchemy session" #98 https://github.com/mitsuhiko/flask-sqlalchemy/blob/master/flask_sqlalchemy/__init__.py#L639 |
Yep, overlaps with #250, closing. |
Hello, I have an interesting use case where I'm building a library of database models as well as a BaseModel and a BaseQuery that I plan on reusing in a bunch of different projects, e.g.
from blahblah_core.models import User
, but I'm struggling conceptually with what to use as my base class. In the library for the reusable models, do I use the flask-sqlalchemyQuery
andModel
bases for all my stuff?AFAIK, those require an instantiated
flask.ext.sqlalchemy.SQLAlchemy()
, even though that doesn't have to be tied to an app object yet. But the other project I'll be using these modules in will also have its ownSQLAlchemy
, right?How do I structure this? Do I just give up and use the blahblah_core
SQLAlchemy
instance in the new project? Or is there a way of decoupling the flask-sqlalchemy extension instance from the Model and Query so that I can use those models with /any/ SQLAlchemy instance? Could I maybe just make them raw SQLAlchemy objects - but then how would I tie those objects in so that flask-sqlalchemy knows about them?Thanks in advance,
~mali
The text was updated successfully, but these errors were encountered: