Files
ai_ml_operations 3a14bfb996 Initial commit
2026-08-27 04:17:34 -07:00

53 lines
1.5 KiB
Python

import uuid
from django.conf import settings
from django.db import models
class TimeStampedModel(models.Model):
"""Abstract base with created/updated timestamps."""
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class UUIDPrimaryKeyModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Meta:
abstract = True
class StoredFile(UUIDPrimaryKeyModel, TimeStampedModel):
"""Binary file blob in the database (no filesystem media storage)."""
class Kind(models.TextChoices):
CAMPAIGN_IMAGE = "campaign_image", "Campaign image"
SOCIAL_IMAGE = "social_image", "Social image"
SOCIAL_VIDEO = "social_video", "Social video"
INVOICE_PDF = "invoice_pdf", "Invoice PDF"
kind = models.CharField(
max_length=32, choices=Kind.choices, default=Kind.CAMPAIGN_IMAGE
)
filename = models.CharField(max_length=255, blank=True)
content_type = models.CharField(max_length=128)
size = models.PositiveIntegerField(default=0)
data = models.BinaryField()
uploaded_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="uploaded_files",
)
class Meta:
ordering = ["-created_at"]
def __str__(self) -> str:
return self.filename or str(self.pk)