I\'d like to use Flask-Migrate and am looking at their example:
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.script imp
Here is an idea. You can create a package model
in which you define classes as individual .py
files. For example, user.py
contains the User
class.
In the __init__.py
file you can define the db
variable. You may also include from user import User
statement so that it would be possible to access User
object directly outside the package. For example you can import the model
package somewhere else in the program using import model
and then use model.User
to directly use the User
class.
To use db
variable directly in the user.py
use from ..model import db
which imports db
variable defined in the __init__.py
file.