I have a module which I want to use for handling database access to both the production and a test database.
The content looks like this:
class FirstModel(db.Model):
#...
class SecondModel(db.Model):
#...
def get_production_connection():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = PRODUCTION_DATABASE_URI
db = SQLAlchemy(app)
return db
def get_test_connection():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = TEST_DATABASE_URI
db = SQLAlchemy(app)
return db
Unfortunately this is not working since the defined models inherit from db.Model which is not defined obviously when the classes are evaluated. Is there any way how I can make the classes/models to inherit from the db.Model class which is only accessible through the db object when one of the methods above is called?