diff --git a/src/pix360core/fields.py b/src/pix360core/fields.py new file mode 100644 index 0000000..2cdc84c --- /dev/null +++ b/src/pix360core/fields.py @@ -0,0 +1,11 @@ +from django.db import models + +class Char32UUIDField(models.UUIDField): + def db_type(self, connection): + return "char(32)" + + def get_db_prep_value(self, value, connection, prepared=False): + value = super().get_db_prep_value(value, connection, prepared) + if value is not None: + value = value.hex + return value diff --git a/src/pix360core/models/content.py b/src/pix360core/models/content.py index dcd9314..ff105f7 100644 --- a/src/pix360core/models/content.py +++ b/src/pix360core/models/content.py @@ -1,6 +1,8 @@ from django.db import models from django.contrib.auth import get_user_model +from ..fields import Char32UUIDField as UUIDField + import mimetypes import uuid @@ -27,7 +29,7 @@ class File(models.Model): is_result (BooleanField): Whether this file is the result of a conversion """ - id = models.UUIDField(primary_key=True, default=uuid.uuid4) + id = UUIDField(primary_key=True, default=uuid.uuid4) file = models.FileField(upload_to=file_upload_path) mime_type = models.CharField(max_length=256, default="application/octet-stream") conversion = models.ForeignKey(to='Conversion', on_delete=models.SET_NULL, null=True, blank=True) @@ -65,7 +67,7 @@ class Conversion(models.Model): log (TextField): Log of the conversion """ - id = models.UUIDField(primary_key=True, default=uuid.uuid4) + id = UUIDField(primary_key=True, default=uuid.uuid4) title = models.CharField(max_length=256, null=True, blank=True) url = models.URLField() downloader = models.CharField(max_length=256, null=True, blank=True)