{"action":"created","issue":{"url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/269","labels_url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/269/labels{/name}","comments_url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/269/comments","events_url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/269/events","html_url":"https://github.com/mitsuhiko/flask-sqlalchemy/issues/269","id":60580989,"number":269,"title":"Creating flask-sqlalchemy models that are reusable","user":{"login":"makmanalp","id":161965,"avatar_url":"https://avatars.githubusercontent.com/u/161965?v=3","gravatar_id":"","url":"https://api.github.com/users/makmanalp","html_url":"https://github.com/makmanalp","followers_url":"https://api.github.com/users/makmanalp/followers","following_url":"https://api.github.com/users/makmanalp/following{/other_user}","gists_url":"https://api.github.com/users/makmanalp/gists{/gist_id}","starred_url":"https://api.github.com/users/makmanalp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/makmanalp/subscriptions","organizations_url":"https://api.github.com/users/makmanalp/orgs","repos_url":"https://api.github.com/users/makmanalp/repos","events_url":"https://api.github.com/users/makmanalp/events{/privacy}","received_events_url":"https://api.github.com/users/makmanalp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-10T22:35:17Z","updated_at":"2015-03-10T22:40:18Z","closed_at":null,"body":"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-sqlalchemy `Query` and `Model` bases for all my stuff?\r\n\r\nAFAIK, 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 own `SQLAlchemy`, right?\r\n\r\nHow 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?\r\n\r\nThanks in advance,\r\n~mali"},"comment":{"url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/comments/78164248","html_url":"https://github.com/mitsuhiko/flask-sqlalchemy/issues/269#issuecomment-78164248","issue_url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/269","id":78164248,"user":{"login":"makmanalp","id":161965,"avatar_url":"https://avatars.githubusercontent.com/u/161965?v=3","gravatar_id":"","url":"https://api.github.com/users/makmanalp","html_url":"https://github.com/makmanalp","followers_url":"https://api.github.com/users/makmanalp/followers","following_url":"https://api.github.com/users/makmanalp/following{/other_user}","gists_url":"https://api.github.com/users/makmanalp/gists{/gist_id}","starred_url":"https://api.github.com/users/makmanalp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/makmanalp/subscriptions","organizations_url":"https://api.github.com/users/makmanalp/orgs","repos_url":"https://api.github.com/users/makmanalp/repos","events_url":"https://api.github.com/users/makmanalp/events{/privacy}","received_events_url":"https://api.github.com/users/makmanalp/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T22:40:18Z","updated_at":"2015-03-10T22:40:18Z","body":"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."}}