2024-11-23 23:02:52 +08:00
|
|
|
from rest_framework import serializers
|
|
|
|
from .models import Document
|
|
|
|
|
|
|
|
|
2024-12-04 02:51:57 +08:00
|
|
|
class DocumentUpdateSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Document
|
|
|
|
fields = [
|
|
|
|
"name",
|
|
|
|
"document_type",
|
|
|
|
"number_pages",
|
2025-01-11 20:03:43 +08:00
|
|
|
"sent_from",
|
|
|
|
"document_month",
|
|
|
|
"document_year",
|
|
|
|
"subject"
|
2024-12-04 02:51:57 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2024-11-23 23:02:52 +08:00
|
|
|
class DocumentUploadSerializer(serializers.ModelSerializer):
|
2024-11-24 02:56:36 +08:00
|
|
|
# For staff document uploads
|
2024-11-23 23:02:52 +08:00
|
|
|
date_uploaded = serializers.DateTimeField(
|
|
|
|
format="%m-%d-%Y %I:%M %p", read_only=True
|
|
|
|
)
|
2024-12-04 02:51:57 +08:00
|
|
|
file = serializers.FileField()
|
2024-11-23 23:02:52 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Document
|
2024-11-24 02:20:18 +08:00
|
|
|
fields = [
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"file",
|
|
|
|
"document_type",
|
|
|
|
"number_pages",
|
2025-01-11 20:03:43 +08:00
|
|
|
"sent_from",
|
|
|
|
"document_month",
|
|
|
|
"document_year",
|
|
|
|
"subject",
|
2024-11-24 02:20:18 +08:00
|
|
|
"date_uploaded",
|
|
|
|
]
|
2025-01-11 20:03:43 +08:00
|
|
|
read_only_fields = ["id", "date_uploaded"]
|
2024-11-23 23:02:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
class DocumentDeleteSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Document
|
|
|
|
fields = ["id"]
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentSerializer(serializers.ModelSerializer):
|
2024-11-24 02:56:36 +08:00
|
|
|
# Read-only serializer without link to the file
|
2024-11-23 23:02:52 +08:00
|
|
|
date_uploaded = serializers.DateTimeField(
|
|
|
|
format="%m-%d-%Y %I:%M %p", read_only=True
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Document
|
2024-12-04 01:29:30 +08:00
|
|
|
fields = [
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"document_type",
|
|
|
|
"number_pages",
|
|
|
|
"ocr_metadata",
|
2025-01-08 13:38:39 +08:00
|
|
|
"sent_from",
|
2024-12-04 01:29:30 +08:00
|
|
|
"date_uploaded",
|
|
|
|
]
|
2024-11-24 02:20:18 +08:00
|
|
|
read_only_fields = [
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"document_type",
|
|
|
|
"number_pages",
|
2024-11-24 14:08:27 +08:00
|
|
|
"ocr_metadata",
|
2025-01-08 13:38:39 +08:00
|
|
|
"sent_from",
|
2024-11-24 02:20:18 +08:00
|
|
|
"date_uploaded",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentFileSerializer(serializers.ModelSerializer):
|
|
|
|
# Read-only serializer which includes the actual link to the file
|
|
|
|
date_uploaded = serializers.DateTimeField(
|
|
|
|
format="%m-%d-%Y %I:%M %p", read_only=True
|
|
|
|
)
|
|
|
|
file = serializers.FileField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Document
|
|
|
|
fields = [
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"document_type",
|
|
|
|
"number_pages",
|
2024-11-24 14:08:27 +08:00
|
|
|
"ocr_metadata",
|
2024-11-24 02:20:18 +08:00
|
|
|
"date_uploaded",
|
2025-01-08 13:38:39 +08:00
|
|
|
"sent_from",
|
2025-01-10 12:54:41 +08:00
|
|
|
"document_month",
|
|
|
|
"document_year",
|
|
|
|
"subject",
|
2024-11-24 14:08:27 +08:00
|
|
|
"file",
|
2024-11-24 02:20:18 +08:00
|
|
|
]
|
|
|
|
read_only_fields = [
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"document_type",
|
|
|
|
"number_pages",
|
2024-11-24 14:08:27 +08:00
|
|
|
"ocr_metadata",
|
2024-11-24 02:20:18 +08:00
|
|
|
"date_uploaded",
|
2025-01-08 13:38:39 +08:00
|
|
|
"sent_from",
|
2025-01-10 12:54:41 +08:00
|
|
|
"document_month",
|
|
|
|
"document_year",
|
|
|
|
"subject",
|
2024-11-24 02:20:18 +08:00
|
|
|
"file",
|
|
|
|
]
|