Browse Source

Add uuid field to games

Colin Powell 3 years ago
parent
commit
fbe0c62d88

+ 2 - 11
games/api/serializers.py

@@ -5,17 +5,8 @@ from rest_framework import serializers
 class GameSerializer(serializers.HyperlinkedModelSerializer):
     class Meta:
         model = Game
-        fields = (
-            "id",
-            "name",
-            "slug",
-            "publisher",
-            "developer",
-            "players",
-            "rating",
-            "game_system",
-            "genre",
-        )
+        fields = '__all__'
+        extra_fields = ['id']
 
 
 class DeveloperSerializer(serializers.HyperlinkedModelSerializer):

+ 44 - 0
games/migrations/0020_developer_uuid_game_uuid_gamecollection_uuid_and_more.py

@@ -0,0 +1,44 @@
+# Generated by Django 4.0.4 on 2022-05-01 18:46
+
+from django.db import migrations, models
+import uuid
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('games', '0019_game_finished_on_game_started_on'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='developer',
+            name='uuid',
+            field=models.UUIDField(default=uuid.uuid4, editable=False),
+        ),
+        migrations.AddField(
+            model_name='game',
+            name='uuid',
+            field=models.UUIDField(default=uuid.uuid4, editable=False),
+        ),
+        migrations.AddField(
+            model_name='gamecollection',
+            name='uuid',
+            field=models.UUIDField(default=uuid.uuid4, editable=False),
+        ),
+        migrations.AddField(
+            model_name='gamesystem',
+            name='uuid',
+            field=models.UUIDField(default=uuid.uuid4, editable=False),
+        ),
+        migrations.AddField(
+            model_name='genre',
+            name='uuid',
+            field=models.UUIDField(default=uuid.uuid4, editable=False),
+        ),
+        migrations.AddField(
+            model_name='publisher',
+            name='uuid',
+            field=models.UUIDField(default=uuid.uuid4, editable=False),
+        ),
+    ]

+ 2 - 0
games/models.py

@@ -1,5 +1,6 @@
 import logging
 import os
+import uuid
 from shlex import quote
 
 from django.conf import settings
@@ -33,6 +34,7 @@ def get_rom_upload_path(instance, filename):
 class BaseModel(TimeStampedModel):
     """A base model for providing name and slugged fields for organizational models"""
 
+    uuid = models.UUIDField(default=uuid.uuid4, editable=False)
     name = models.CharField(max_length=255)
     slug = AutoSlugField(populate_from="name")