Browse Source

Add uuid fields for slugs at some point

Colin Powell 2 năm trước cách đây
mục cha
commit
4dc1599633

+ 35 - 0
vrobbler/apps/music/migrations/0003_album_uuid_artist_uuid_track_uuid.py

@@ -0,0 +1,35 @@
+# Generated by Django 4.1.5 on 2023-01-08 21:31
+
+from django.db import migrations, models
+import uuid
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('music', '0002_alter_album_year'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='album',
+            name='uuid',
+            field=models.UUIDField(
+                blank=True, default=uuid.uuid4, editable=False, null=True
+            ),
+        ),
+        migrations.AddField(
+            model_name='artist',
+            name='uuid',
+            field=models.UUIDField(
+                blank=True, default=uuid.uuid4, editable=False, null=True
+            ),
+        ),
+        migrations.AddField(
+            model_name='track',
+            name='uuid',
+            field=models.UUIDField(
+                blank=True, default=uuid.uuid4, editable=False, null=True
+            ),
+        ),
+    ]

+ 6 - 2
vrobbler/apps/music/models.py

@@ -1,15 +1,17 @@
 import logging
 from typing import Dict, Optional
+from uuid import uuid4
+
 from django.db import models
-from django_extensions.db.models import TimeStampedModel
 from django.utils.translation import gettext_lazy as _
-from vrobbler.apps.music.constants import JELLYFIN_POST_KEYS as KEYS
+from django_extensions.db.models import TimeStampedModel
 
 logger = logging.getLogger(__name__)
 BNULL = {"blank": True, "null": True}
 
 
 class Album(TimeStampedModel):
+    uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
     name = models.CharField(max_length=255)
     year = models.IntegerField(**BNULL)
     musicbrainz_id = models.CharField(max_length=255, **BNULL)
@@ -25,6 +27,7 @@ class Album(TimeStampedModel):
 
 
 class Artist(TimeStampedModel):
+    uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
     name = models.CharField(max_length=255)
     musicbrainz_id = models.CharField(max_length=255, **BNULL)
 
@@ -37,6 +40,7 @@ class Artist(TimeStampedModel):
 
 
 class Track(TimeStampedModel):
+    uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
     title = models.CharField(max_length=255, **BNULL)
     artist = models.ForeignKey(Artist, on_delete=models.DO_NOTHING)
     album = models.ForeignKey(Album, on_delete=models.DO_NOTHING, **BNULL)

+ 28 - 0
vrobbler/apps/videos/migrations/0004_series_uuid_video_uuid.py

@@ -0,0 +1,28 @@
+# Generated by Django 4.1.5 on 2023-01-08 21:31
+
+from django.db import migrations, models
+import uuid
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('videos', '0003_alter_video_run_time_ticks'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='series',
+            name='uuid',
+            field=models.UUIDField(
+                blank=True, default=uuid.uuid4, editable=False, null=True
+            ),
+        ),
+        migrations.AddField(
+            model_name='video',
+            name='uuid',
+            field=models.UUIDField(
+                blank=True, default=uuid.uuid4, editable=False, null=True
+            ),
+        ),
+    ]

+ 9 - 3
vrobbler/apps/videos/models.py

@@ -1,17 +1,22 @@
 import logging
-from typing import Dict, Tuple
+from typing import Dict
+from uuid import uuid4
+
 from django.db import models
-from django_extensions.db.models import TimeStampedModel
 from django.utils.translation import gettext_lazy as _
+from django_extensions.db.models import TimeStampedModel
 
 logger = logging.getLogger(__name__)
 BNULL = {"blank": True, "null": True}
 
 
 class Series(TimeStampedModel):
+    uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
     name = models.CharField(max_length=255)
     overview = models.TextField(**BNULL)
     tagline = models.TextField(**BNULL)
+    # tvdb_id = models.CharField(max_length=20, **BNULL)
+    # imdb_id = models.CharField(max_length=20, **BNULL)
 
     def __str__(self):
         return self.name
@@ -30,12 +35,13 @@ class Video(TimeStampedModel):
         MOVIE = 'M', _('Movie')
 
     # General fields
+    uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
+    title = models.CharField(max_length=255, **BNULL)
     video_type = models.CharField(
         max_length=1,
         choices=VideoType.choices,
         default=VideoType.UNKNOWN,
     )
-    title = models.CharField(max_length=255, **BNULL)
     overview = models.TextField(**BNULL)
     tagline = models.TextField(**BNULL)
     run_time = models.CharField(max_length=8, **BNULL)