feat: add django-channel and daphne

This commit is contained in:
2026-05-25 00:42:34 +02:00
parent f543cdcd5c
commit c2602dbc02
8 changed files with 1158 additions and 43 deletions
+69 -18
View File
@@ -6,6 +6,13 @@ import uuid
from accounts.models import CustomUser
class OCRStatus(models.TextChoices):
TO_PROCESS = "to_process", _("To Process")
PROCESSING = "processing", _("Processing")
PROCESSED = "processed", _("Processed")
ERROR = "error", _("Error processing")
def submission_file_upload_path(instance, filename):
ext = filename.split(".")[-1] if "." in filename else ""
@@ -14,9 +21,18 @@ def submission_file_upload_path(instance, filename):
return f"submissions/{instance.submission.id}/{new_filename}"
class Submission(models.Model):
class BaseModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# Timestamps
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class Submission(BaseModel):
user = models.ForeignKey(
CustomUser,
on_delete=models.CASCADE,
@@ -33,14 +49,8 @@ class Submission(models.Model):
help_text="Optional notes about the submission",
)
# Timestamps
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class SubmissionFile(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class SubmissionFile(BaseModel):
submission = models.ForeignKey(
Submission,
on_delete=models.CASCADE,
@@ -53,7 +63,8 @@ class SubmissionFile(models.Model):
)
original_filename = models.CharField(
max_length=255, help_text=_("Original filename as uploaded by user")
max_length=255,
help_text=_("Original filename as uploaded by user"),
)
file_size = models.PositiveIntegerField(help_text=_("File size in bytes"))
content_type = models.CharField(
@@ -62,17 +73,16 @@ class SubmissionFile(models.Model):
)
# OCR metadata
ocr_processed = models.BooleanField(
default=False, help_text="Whether OCR has been processed for this file"
ocr_status = models.CharField(
max_length=20,
choices=OCRStatus.choices,
default=OCRStatus.TO_PROCESS,
help_text=_("OCR processing status for the entire file"),
)
ocr_raw_data = models.JSONField(
null=True, blank=True, help_text="Raw OCR data as JSON"
ocr_raw_data = models.TextField(
blank=True,
help_text=_("Raw OCR data for the entire file"),
)
ocr_error = models.TextField(blank=True, help_text="OCR processing error message")
# Timestamps
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["file", "created_at"]
@@ -89,3 +99,44 @@ class SubmissionFile(models.Model):
self.file_size = self.file.size
super().save(*args, **kwargs)
class ImageCrop(BaseModel):
submission_file = models.ForeignKey(
SubmissionFile,
on_delete=models.CASCADE,
related_name="crops",
)
# Crop coordinates (pixels): x1, y1, x2, y2
x1 = models.PositiveIntegerField(help_text=_("Top-left x coordinate"))
y1 = models.PositiveIntegerField(help_text=_("Top-left y coordinate"))
x2 = models.PositiveIntegerField(help_text=_("Bottom-right x coordinate"))
y2 = models.PositiveIntegerField(help_text=_("Bottom-right y coordinate"))
# Label/name for the crop
label = models.CharField(
max_length=255,
blank=True,
help_text=_("Optional label for this crop region"),
)
# OCR results for this crop
ocr_status = models.CharField(
max_length=20,
choices=OCRStatus.choices,
default=OCRStatus.TO_PROCESS,
help_text=_("OCR processing status for this crop"),
)
ocr_raw_data = models.TextField(
blank=True,
help_text=_("Raw OCR data for this crop"),
)
class Meta:
ordering = ["created_at"]
verbose_name = "Image Crop"
verbose_name_plural = "Image Crops"
def __str__(self):
return f"{self.label or f'Crop ({self.x1}, {self.y1}, {self.x2}, {self.y2})'}"