diff --git a/accountant/__init__.py b/accountant/__init__.py index 6da9cb1..02706a1 100644 --- a/accountant/__init__.py +++ b/accountant/__init__.py @@ -22,7 +22,8 @@ from flask_alembic import Alembic from flask_alembic.cli.click import cli as alembic_cli from flask_restplus import Api from flask_cors import CORS -from flask_sqlalchemy import SQLAlchemy + +from .models import db # The app app = Flask(__name__, static_folder=None, template_folder=None) @@ -34,8 +35,7 @@ app.config['SQLALCHEMY_ECHO'] = app.debug app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True -# Database initialization. -db = SQLAlchemy(app) +db.init_app(app) # Database migrations. alembic = Alembic(app) diff --git a/accountant/models/__init__.py b/accountant/models/__init__.py index 43a4ef3..9a4debc 100644 --- a/accountant/models/__init__.py +++ b/accountant/models/__init__.py @@ -16,7 +16,12 @@ """ import pkgutil -__all__ = [] +from flask_sqlalchemy import SQLAlchemy + +# pylint: disable=invalid-name +db = SQLAlchemy() + +__all__ = ['db'] for loader, module_name, is_pkg in pkgutil.walk_packages(__path__): __all__.append(module_name) diff --git a/accountant/models/accounts.py b/accountant/models/accounts.py index 1662d81..51aba35 100644 --- a/accountant/models/accounts.py +++ b/accountant/models/accounts.py @@ -14,7 +14,8 @@ You should have received a copy of the GNU Affero General Public License along with Accountant. If not, see . """ -from accountant import db +# pylint: disable=no-member,too-few-public-methods +from . import db from .operations import Operation diff --git a/accountant/models/operations.py b/accountant/models/operations.py index 15db841..3c3e970 100644 --- a/accountant/models/operations.py +++ b/accountant/models/operations.py @@ -18,7 +18,8 @@ from datetime import date import arrow -from accountant import db +# pylint: disable=no-member,too-few-public-methods +from . import db class Operation(db.Model): diff --git a/accountant/models/scheduled_operations.py b/accountant/models/scheduled_operations.py index eef1c1c..e760b1a 100644 --- a/accountant/models/scheduled_operations.py +++ b/accountant/models/scheduled_operations.py @@ -18,7 +18,8 @@ from calendar import monthrange import arrow -from accountant import db +# pylint: disable=no-member,too-few-public-methods,too-many-instance-attributes +from . import db from .accounts import Account from .operations import Operation diff --git a/accountant/models/users.py b/accountant/models/users.py index 244cd22..f720c07 100644 --- a/accountant/models/users.py +++ b/accountant/models/users.py @@ -23,7 +23,8 @@ from flask import current_app as app from flask_login import UserMixin -from accountant import db +# pylint: disable=no-member,too-few-public-methods +from . import db class User(UserMixin, db.Model):