Adding completed_at and winners to g ames

This commit is contained in:
ryan
2026-01-24 09:57:25 -05:00
parent e431ba45e9
commit d4345a4e09
5 changed files with 159 additions and 27 deletions

View File

@@ -114,6 +114,8 @@ class Game(db.Model):
current_question_index = db.Column(db.Integer, default=0) # Track current question
is_template = db.Column(db.Boolean, default=False) # Mark as reusable template
current_turn_team_id = db.Column(db.Integer, db.ForeignKey('teams.id'), nullable=True) # Track whose turn it is
completed_at = db.Column(db.DateTime, nullable=True) # When game ended
winners = db.Column(db.JSON, nullable=True) # [{"team_name": str, "score": int}, ...]
# Relationships
teams = db.relationship('Team', back_populates='game', cascade='all, delete-orphan',
@@ -146,7 +148,9 @@ class Game(db.Model):
'total_questions': len(self.game_questions),
'is_template': self.is_template,
'current_turn_team_id': self.current_turn_team_id,
'current_turn_team_name': self.current_turn_team.name if self.current_turn_team else None
'current_turn_team_name': self.current_turn_team.name if self.current_turn_team else None,
'completed_at': self.completed_at.isoformat() if self.completed_at else None,
'winners': self.winners
}
if include_questions:
@@ -194,7 +198,7 @@ class Team(db.Model):
phone_a_friend_count = db.Column(db.Integer, default=5) # Number of phone-a-friend lifelines
# Relationships
game = db.relationship('Game', back_populates='teams')
game = db.relationship('Game', back_populates='teams', foreign_keys=[game_id])
scores = db.relationship('Score', back_populates='team', cascade='all, delete-orphan')
@property