[videos] Make imdb_id and youtube_id unique together
This commit is contained in:
@ -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