Browse Source

Replace relation between user and notification_player with game_player and notification_player

testing
Burathar 4 years ago
parent
commit
15c27bbfdc
  1. 11
      app/models/game_player.py
  2. 4
      app/models/notification.py
  3. 4
      app/models/notification_player.py

11
app/models/game_player.py

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
from sqlalchemy.ext.associationproxy import association_proxy
from app import db
from app.models import Role
from app.models import Role, NotificationPlayer
class GamePlayer(db.Model):
__tablename__ = 'game_player'
@ -9,3 +11,10 @@ class GamePlayer(db.Model): @@ -9,3 +11,10 @@ class GamePlayer(db.Model):
role = db.Column(db.Enum(Role), server_default=Role(0).name, nullable=False)
game = db.relationship('Game', back_populates='game_players')
user = db.relationship('User', back_populates='user_games')
player_notifications = db.relationship(
'NotificationPlayer',
back_populates='recipient',
cascade='save-update, merge, delete, delete-orphan')
notifications = association_proxy('player_notifications', 'notification',
creator=lambda notification: NotificationPlayer(notification=notification))

4
app/models/notification.py

@ -16,5 +16,5 @@ class Notification(db.Model): @@ -16,5 +16,5 @@ class Notification(db.Model):
'NotificationPlayer',
back_populates='notification',
cascade='save-update, merge, delete, delete-orphan')
recipients = association_proxy('notification_recipients', 'player',
creator=lambda player: NotificationPlayer(recipient=player))
recipients = association_proxy('notification_recipients', 'game_player',
creator=lambda game_player: NotificationPlayer(recipient=game_player))

4
app/models/notification_player.py

@ -3,8 +3,8 @@ from app import db @@ -3,8 +3,8 @@ from app import db
class NotificationPlayer(db.Model):
__tablename__ = 'notification_player'
notification_id = db.Column(db.Integer, db.ForeignKey('notification.id'), primary_key=True, nullable=False)
player_id = db.Column(db.Integer, db.ForeignKey('player.id'), primary_key=True, nullable=False)
game_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), primary_key=True, nullable=False)
been_shown = db.Column(db.Boolean, server_default='True', nullable=False)
notification = db.relationship('Notification', back_populates='notification_recipients')
recipient = db.relationship('Player', back_populates='player_notifications')
recipient = db.relationship('GamePlayer', back_populates='player_notifications')
Loading…
Cancel
Save