ft_transcendence/games/models.py

21 lines
626 B
Python
Raw Normal View History

2023-12-12 06:06:13 -05:00
from django.db import models
# Create your models here.
class GameModel(models.Model):
2023-12-20 13:11:56 -05:00
finished = models.BooleanField(default=False)
started = models.BooleanField(default=False)
winner_id = models.IntegerField(default=-1)
2023-12-12 06:06:13 -05:00
2023-12-26 15:32:20 -05:00
def create(self, players_id: [int]):
2023-12-12 06:06:13 -05:00
self.save()
2023-12-26 15:32:20 -05:00
for player_id in players_id:
GameMembersModel(game_id = self.pk, player_id = player_id).save()
2023-12-12 06:06:13 -05:00
return self.pk
2023-12-20 13:11:56 -05:00
2023-12-26 15:32:20 -05:00
def get_players_id(self):
return [game_member.member_id for game_member in GameMembersModel.objects.filter(self.pk)]
2023-12-12 06:06:13 -05:00
class GameMembersModel(models.Model):
game_id = models.IntegerField()
2023-12-26 15:32:20 -05:00
player_id = models.IntegerField()