2023-12-20 13:15:47 -05:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from games.models import GameModel
|
|
|
|
|
|
|
|
# Create your models here.tu
|
|
|
|
class TournamentModel(models.Model):
|
|
|
|
|
2023-12-20 15:11:37 -05:00
|
|
|
name = models.CharField(max_length=100)
|
2023-12-20 13:15:47 -05:00
|
|
|
nb_players = models.IntegerField()
|
|
|
|
nb_players_by_game = models.IntegerField()
|
|
|
|
level = models.IntegerField()
|
|
|
|
started = models.BooleanField(default=False)
|
|
|
|
finished = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
def create_game(self, users_id):
|
|
|
|
game_id = GameModel.create(users_id=users_id)
|
|
|
|
TournamentGamesModel(game_id=game_id, tournament_id=self.pk).save()
|
|
|
|
return game_id
|
|
|
|
|
|
|
|
def get_games_id_by_level(self, level):
|
|
|
|
return list(TournamentGamesModel.objects.filter(tournament_id=self.pk, tournament_level=level))
|
|
|
|
|
|
|
|
def get_games_id(self):
|
|
|
|
return list(TournamentGamesModel.objects.filter(tournament_id=self.pk))
|
|
|
|
|
|
|
|
def get_players_id(self):
|
|
|
|
lst: [int] = []
|
|
|
|
for game_id in self.get_games_id():
|
|
|
|
lst.append(GameMembersModel.objects.filter(game_id=game_id))
|
|
|
|
return lst
|
|
|
|
|
|
|
|
class TournamentGamesModel(models.Model):
|
|
|
|
|
|
|
|
tournament_id = models.IntegerField()
|
|
|
|
tournament_level = models.IntegerField()
|
|
|
|
game_id = models.IntegerField()
|