feat: Introduces Char32UUIDField for model UUIDs
Adds a custom UUIDField to use 32-character format for IDs to optimize database storage and integration with existing systems. Refactors model definitions to replace default UUIDField with the new Char32UUIDField to maintain consistent implementation across the codebase.
This commit is contained in:
parent
00a923fe20
commit
a95fffbdf5
2 changed files with 15 additions and 2 deletions
11
src/pix360core/fields.py
Normal file
11
src/pix360core/fields.py
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue