Skip to content

Commit

Permalink
fix constraint for Logic hints
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Dec 6, 2023
1 parent 3e79d2f commit 3a56a7e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,12 @@ class LogicPuzzleHint(models.Model):
notes = models.TextField(help_text="Internal notes", blank=True)
qr_index = models.IntegerField(
help_text="The index of the QR code that this hint is for, that is everyone on their nth QR code will get same same hint (starting from 1)",
unique=True,
)

hunt = models.ForeignKey(
Hunt, related_name="logic_puzzle", on_delete=models.CASCADE
)

def __str__(self):
return str(self.hint)

Expand All @@ -375,7 +374,13 @@ def get_clue(cls, team: Team) -> str | None:
return hint.hint
except cls.DoesNotExist:
return None

class Meta:
constraints = [
models.UniqueConstraint(
fields=["qr_index", "hunt"],
name="unique_qr_index_name_per_hunt",
)
]

@receiver(m2m_changed, sender=Team)
def remove_empty_teams(sender, instance: Team, action, **kwargs):
Expand Down

0 comments on commit 3a56a7e

Please sign in to comment.