Add additional scanning metadata and sorting for documents

This commit is contained in:
Keannu Christian Bernasol 2025-01-09 00:43:55 +08:00
parent 674a7ec592
commit 41507aa550
5 changed files with 126 additions and 45 deletions

View file

@ -7,5 +7,7 @@ from .models import Document
@admin.register(Document)
class DocumentAdmin(ModelAdmin):
model = Document
search_fields = ["id", "name", "document_type"]
list_display = ["id", "name", "document_type", "date_uploaded"]
search_fields = ["id", "name", "subject", "sent_from", "document_year",
"document_month", "document_type"]
list_display = ["id", "name", "subject", "sent_from", "document_year",
"document_month", "document_type", "date_uploaded"]

View file

@ -0,0 +1,28 @@
# Generated by Django 5.1.3 on 2025-01-08 14:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("documents", "0004_rename_memorandum_from_document_sent_from"),
]
operations = [
migrations.AddField(
model_name="document",
name="document_month",
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name="document",
name="document_year",
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name="document",
name="subject",
field=models.CharField(blank=True, max_length=128, null=True),
),
]

View file

@ -12,12 +12,21 @@ class Document(models.Model):
sent_from = models.CharField(
max_length=128, null=True, blank=True
)
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
)
number_pages = models.IntegerField(null=False, blank=False)
ocr_metadata = models.TextField(null=True, blank=True)
def upload_to(instance, filename):
_, extension = filename.rsplit(".", 1)
return "documents/%s_%s.%s" % (now(), str(uuid.uuid4()), extension)
return f"documents/{instance.document_type}/{instance.document_year}/{str(uuid.uuid4())}.{extension}"
file = models.FileField(upload_to=upload_to)