Refactor group and music game models to use UniqueConstraint; update form error handling in templates
This commit is contained in:
parent
43ec6aafc4
commit
245a2503e2
5 changed files with 84 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.db.models.functions import Lower
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
|
@ -19,7 +20,9 @@ class Group(models.Model):
|
|||
return reverse("group_detail", kwargs={"pk": self.pk})
|
||||
|
||||
class Meta:
|
||||
unique_together = ["name", "owner"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(Lower("name"), "owner", name="unique_group_name")
|
||||
]
|
||||
|
||||
|
||||
class MusicVideo(models.Model):
|
||||
|
@ -31,7 +34,11 @@ class MusicVideo(models.Model):
|
|||
blacklisted = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
unique_together = ["yt_id", "owner", "group"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=("yt_id", "owner", "group"), name="unique_music_in_group"
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class MusikGame(models.Model):
|
||||
|
@ -52,5 +59,10 @@ class MusicGameOrder(models.Model):
|
|||
order = models.PositiveIntegerField()
|
||||
|
||||
class Meta:
|
||||
unique_together = [["game", "player", "music_video"], ["game", "order"]]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=("game", "player", "music_video"), name="unique_music_in_game"
|
||||
),
|
||||
models.UniqueConstraint(fields=("game", "order"), name="unique_order"),
|
||||
]
|
||||
ordering = ["order"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue