[videos] Make imdb_id and youtube_id unique together
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
# Generated by Django 4.2.29 on 2026-03-22 17:02
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("videos", "0025_add_imdb_id_unique"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="video",
|
||||
name="imdb_id",
|
||||
field=models.CharField(blank=True, max_length=20, null=True),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="video",
|
||||
constraint=models.UniqueConstraint(
|
||||
condition=models.Q(
|
||||
models.Q(("imdb_id__isnull", True), _negated=True),
|
||||
models.Q(("youtube_id__isnull", True), _negated=True),
|
||||
_connector="OR",
|
||||
),
|
||||
fields=("imdb_id", "youtube_id"),
|
||||
name="unique_imdb_or_youtube_id",
|
||||
),
|
||||
),
|
||||
]
|
||||
@ -261,7 +261,7 @@ class Video(ScrobblableMixin):
|
||||
season_number = models.IntegerField(**BNULL)
|
||||
episode_number = models.IntegerField(**BNULL)
|
||||
next_imdb_id = models.CharField(max_length=20, **BNULL)
|
||||
imdb_id = models.CharField(max_length=20, **BNULL, unique=True)
|
||||
imdb_id = models.CharField(max_length=20, **BNULL)
|
||||
imdb_rating = models.FloatField(**BNULL)
|
||||
tmdb_rating = models.FloatField(**BNULL)
|
||||
cover_image = models.ImageField(upload_to="videos/video/", **BNULL)
|
||||
@ -293,6 +293,16 @@ class Video(ScrobblableMixin):
|
||||
return f"{self.title} / {self.channel}"
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["imdb_id", "youtube_id"],
|
||||
name="unique_imdb_or_youtube_id",
|
||||
condition=~models.Q(imdb_id__isnull=True)
|
||||
| ~models.Q(youtube_id__isnull=True),
|
||||
),
|
||||
]
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("videos:video_detail", kwargs={"slug": self.uuid})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user