from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.sql import func from app import db from .notification_player import NotificationPlayer class Notification(db.Model): __tablename__ = 'notification' id = db.Column(db.Integer, primary_key=True) game_id = db.Column(db.Integer, db.ForeignKey('game.id'), nullable=False) message = db.Column(db.Text, nullable=False) type = db.Column(db.String(64), nullable=False, default='General') timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False) notification_recipients = db.relationship( 'NotificationPlayer', back_populates='notification', cascade='save-update, merge, delete, delete-orphan') recipients = association_proxy('notification_recipients', 'game_player', creator=lambda game_player: NotificationPlayer(recipient=game_player))