import uuid from django.db import models class Team(models.Model): """ Represent a team participating in the event """ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=32) validated_flags = models.ManyToManyField(to="Flag", blank=True, related_name="validated_by_teams") def __str__(self): return f"<{self.__class__.__name__}({self.name!r}, {self.id!r})>" class Flag(models.Model): """ Represent a flag that can be validated by the team """ class FlagType(models.IntegerChoices): NORMAL = 0 BONUS = 1 MALUS = 2 id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) # the flag might depend on other flags parents = models.ManyToManyField( "self", blank=True, symmetrical=False, related_name="children", ) # information about the flags # TODO(Faraphel): store code as hash ? code = models.CharField(max_length=32) # the password that must be given to obtain the flag name = models.CharField(max_length=32) # the name of the flag description = models.TextField() # the description on how to obtain the flag # TODO(Faraphel): replace with or add a points amount you gain ? type = models.IntegerField(choices=FlagType.choices, default=FlagType.NORMAL) def __str__(self): return f"<{self.__class__.__name__}({self.name!r}, {self.id!r})>" class Hint(models.Model): """ Represent a hint that can be given to a team """ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) importance = models.PositiveIntegerField() description = models.TextField() penalty = models.PositiveIntegerField() flag = models.ForeignKey(to=Flag, on_delete=models.CASCADE, related_name="hints") def __str__(self): return f"<{self.__class__.__name__}({self.flag.name!r}, {self.id!r})>"