class Match(db.Model): id = db.Column(db.Integer, primary_key=True) first_team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False) first_team = db.relationship("Team", foreign_keys=[first_team_id]) first_team_score = db.Column(db.Integer, nullable=False) second_team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False) second_team = db.relationship("Team", foreign_keys=[second_team_id]) second_team_score = db.Column(db.Integer, nullable=False) team1_pos = db.Column(db.String(5)) team2_pos = db.Column(db.String(5)) date = db.Column(db.String(120), nullable=False) players_stats = db.relationship("Match_Player_Stats", backref='match', lazy=True) def team_won(self): if self.first_team_score > self.second_team_score: return self.first_team elif self.first_team_score < self.second_team_score: return self.second_team else: return "Draw" def __repr__(self): return f"{self.first_team} {self.first_team_score} - {self.second_team_score} {self.second_team}"
class Upcoming_Match(db.Model): uuid = db.Column(db.String(512), primary_key=True) team1 = db.Column(db.String(120), nullable=False) team2 = db.Column(db.String(120), nullable=False) date = db.Column(db.String(50), nullable=False) def __repr__(self): return self.team1 + " vs " + self.team2
class Player(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) age = db.Column(db.Integer, nullable=False) nationality = db.Column(db.String(120), nullable=False) shirt_number = db.Column(db.String(5)) total_matches = db.Column(db.Integer) total_goals = db.Column(db.Integer) total_assists = db.Column(db.Integer) team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False) games_stats = db.relationship('Match_Player_Stats', backref='player', lazy=True) def __repr__(self): return f"{self.name}"
class Team(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) points = db.Column(db.Integer, nullable=False) wins = db.Column(db.Integer, nullable=False) draws = db.Column(db.Integer, nullable=False) loses = db.Column(db.Integer, nullable=False) goals_scored = db.Column(db.Integer, nullable=False) goals_concended = db.Column(db.Integer, nullable=False) short_name = db.Column(db.String(10), nullable=False) nickname = db.Column(db.String(120), nullable=False) players = db.relationship("Player", backref="team", lazy=True) def last_five(self): matches = Match.query.filter(or_(Match.first_team_id == self.id, Match.second_team_id == self.id)).all()[-5:] return matches def __repr__(self): return f"{self.name}"
class Used_Link(db.Model): used_link = db.Column(db.String(1024), nullable=False, primary_key=True) def __repr__(self): return self.used_link