From bbb5504dadf44db0a70bd4ff9e5dcf07629bfe00 Mon Sep 17 00:00:00 2001 From: Burathar Date: Sat, 18 Jul 2020 22:48:00 +0200 Subject: [PATCH] make model modules itself import each other with relative imports --- app/models/__init__.py | 25 ++++++++++--------------- app/models/game.py | 4 +++- app/models/game_player.py | 5 ++++- app/models/notification.py | 2 +- app/models/objective.py | 3 ++- app/models/user.py | 13 +++++++------ 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/models/__init__.py b/app/models/__init__.py index ccb5cd3..4dc5393 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -1,16 +1,11 @@ -from app import login -from app.models.game import Game -from app.models.game_player import GamePlayer -from app.models.game_state import GameState -from app.models.location import Location, LocationEncoder -from app.models.notification_player import NotificationPlayer -from app.models.objective import Objective, ObjectiveMinimalEncoder -from app.models.player_caught_player import PlayerCaughtPlayer -from app.models.player_found_objective import PlayerFoundObjective -from app.models.role import Role -from app.models.user import User - -@login.user_loader -def load_user(id): - return User.query.get(int(id)) +from .game import Game +from .game_player import GamePlayer +from .game_state import GameState +from .location import Location, LocationEncoder +from .notification_player import NotificationPlayer +from .objective import Objective, ObjectiveMinimalEncoder +from .player_caught_player import PlayerCaughtPlayer +from .player_found_objective import PlayerFoundObjective +from .role import Role +from .user import User diff --git a/app/models/game.py b/app/models/game.py index 560822d..a22c088 100644 --- a/app/models/game.py +++ b/app/models/game.py @@ -1,6 +1,8 @@ from sqlalchemy.ext.associationproxy import association_proxy from app import db -from app.models import GameState, GamePlayer, Role +from .game_state import GameState +from .game_player import GamePlayer +from .role import Role class Game(db.Model): __tablename__ = 'game' diff --git a/app/models/game_player.py b/app/models/game_player.py index f194c49..7b45910 100644 --- a/app/models/game_player.py +++ b/app/models/game_player.py @@ -1,7 +1,10 @@ from sqlalchemy.ext.associationproxy import association_proxy from app import db -from app.models import Role, NotificationPlayer, PlayerFoundObjective, PlayerCaughtPlayer +from .role import Role +from .notification_player import NotificationPlayer +from .player_found_objective import PlayerFoundObjective +from .player_caught_player import PlayerCaughtPlayer class GamePlayer(db.Model): __tablename__ = 'game_player' diff --git a/app/models/notification.py b/app/models/notification.py index 53ea321..55eb5d7 100644 --- a/app/models/notification.py +++ b/app/models/notification.py @@ -2,7 +2,7 @@ from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.sql import func from app import db -from app.models import NotificationPlayer +from .notification_player import NotificationPlayer class Notification(db.Model): __tablename__ = 'notification' diff --git a/app/models/objective.py b/app/models/objective.py index de24ddd..63cf666 100644 --- a/app/models/objective.py +++ b/app/models/objective.py @@ -3,7 +3,8 @@ from json import JSONEncoder from sqlalchemy.ext.associationproxy import association_proxy from app import db -from app.models import PlayerFoundObjective, Role +from .player_found_objective import PlayerFoundObjective +from .role import Role class Objective(db.Model): """ !Always call set_hash after() creating new instance! """ diff --git a/app/models/user.py b/app/models/user.py index 2262a52..039ad05 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -5,8 +5,8 @@ from flask_login import UserMixin from sqlalchemy.ext.associationproxy import association_proxy from werkzeug.security import generate_password_hash, check_password_hash -from app import db -from app.models import GamePlayer, PlayerFoundObjective, PlayerCaughtPlayer, NotificationPlayer, Role +from app import db, login +from app.models import GamePlayer, Role class User(UserMixin, db.Model): """ !Always call set_auth_hash() after creating new instance! """ @@ -24,10 +24,6 @@ class User(UserMixin, db.Model): creator=lambda game: GamePlayer(game=game)) - - - - locations = db.relationship( 'Location', lazy='select', @@ -78,3 +74,8 @@ class User(UserMixin, db.Model): def delete_orphans(): User.query.filter(~User.user_games.any()).delete() db.session.commit() + + +@login.user_loader +def load_user(id): + return User.query.get(int(id)) \ No newline at end of file