70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
from django.contrib import admin
|
|
from .models import Submission, SubmissionFile
|
|
|
|
|
|
class SubmissionFileInline(admin.TabularInline):
|
|
model = SubmissionFile
|
|
extra = 0
|
|
fields = [
|
|
"original_filename",
|
|
"file_size",
|
|
"content_type",
|
|
"ocr_processed",
|
|
"ocr_error",
|
|
"created_at",
|
|
]
|
|
readonly_fields = [
|
|
"file_size",
|
|
"content_type",
|
|
"ocr_processed",
|
|
"ocr_error",
|
|
"created_at",
|
|
]
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request)
|
|
|
|
|
|
@admin.register(Submission)
|
|
class SubmissionAdmin(admin.ModelAdmin):
|
|
list_display = ["id_short", "user", "notes_preview", "created_at"]
|
|
list_filter = ["created_at", "updated_at"]
|
|
search_fields = ["id", "user__email", "notes"]
|
|
readonly_fields = ["id", "created_at", "updated_at"]
|
|
inlines = [SubmissionFileInline]
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related("user")
|
|
|
|
@admin.display(description="ID")
|
|
def id_short(self, obj):
|
|
return str(obj.id)[:8]
|
|
|
|
@admin.display(description="Notes")
|
|
def notes_preview(self, obj):
|
|
if obj.notes:
|
|
return obj.notes[:50] + "..." if len(obj.notes) > 50 else obj.notes
|
|
return "-"
|
|
|
|
|
|
@admin.register(SubmissionFile)
|
|
class SubmissionFileAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"original_filename",
|
|
"submission_id",
|
|
"file_size",
|
|
"content_type",
|
|
"ocr_processed",
|
|
"created_at",
|
|
]
|
|
list_filter = ["content_type", "ocr_processed", "created_at"]
|
|
search_fields = ["original_filename", "submission__id"]
|
|
readonly_fields = ["file_size", "content_type", "created_at", "updated_at"]
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related("submission")
|
|
|
|
@admin.display(description="Submission ID")
|
|
def submission_id(self, obj):
|
|
return str(obj.submission.id)[:8]
|