2024-11-23 23:02:52 +08:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.timezone import now
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
class Document(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
document_type = models.CharField(
|
2024-12-04 15:39:39 +08:00
|
|
|
max_length=128, null=False, blank=False
|
2024-11-23 23:02:52 +08:00
|
|
|
)
|
2025-01-08 13:38:39 +08:00
|
|
|
sent_from = models.CharField(
|
|
|
|
max_length=128, null=True, blank=True
|
|
|
|
)
|
2025-01-09 00:43:55 +08:00
|
|
|
document_month = models.CharField(
|
|
|
|
max_length=128, null=True, blank=True
|
|
|
|
)
|
|
|
|
document_year = models.CharField(
|
|
|
|
max_length=128, null=True, blank=True
|
|
|
|
)
|
|
|
|
subject = models.CharField(
|
|
|
|
max_length=128, null=True, blank=True
|
|
|
|
)
|
2024-11-24 02:20:18 +08:00
|
|
|
number_pages = models.IntegerField(null=False, blank=False)
|
2024-11-24 14:08:27 +08:00
|
|
|
ocr_metadata = models.TextField(null=True, blank=True)
|
2024-11-23 23:02:52 +08:00
|
|
|
|
|
|
|
def upload_to(instance, filename):
|
2024-12-04 02:51:57 +08:00
|
|
|
_, extension = filename.rsplit(".", 1)
|
2025-01-09 00:43:55 +08:00
|
|
|
return f"documents/{instance.document_type}/{instance.document_year}/{str(uuid.uuid4())}.{extension}"
|
2024-11-23 23:02:52 +08:00
|
|
|
|
|
|
|
file = models.FileField(upload_to=upload_to)
|
|
|
|
|
|
|
|
date_uploaded = models.DateTimeField(default=now, editable=False)
|
|
|
|
|
|
|
|
def __str__(self):
|
2024-11-24 02:20:18 +08:00
|
|
|
return f"{self.name} ({self.document_type})"
|