107 lines
2.9 KiB
Python
107 lines
2.9 KiB
Python
from django.contrib import admin
|
|
from .models import Submission, SubmissionFile, ImageCrop
|
|
|
|
|
|
class ImageCropInline(admin.TabularInline):
|
|
model = ImageCrop
|
|
extra = 1
|
|
fields = [
|
|
"label",
|
|
"x1",
|
|
"y1",
|
|
"x2",
|
|
"y2",
|
|
"ocr_status",
|
|
"created_at",
|
|
]
|
|
readonly_fields = ["created_at"]
|
|
|
|
|
|
class SubmissionFileInline(admin.TabularInline):
|
|
model = SubmissionFile
|
|
extra = 0
|
|
fields = [
|
|
"original_filename",
|
|
"file_size",
|
|
"content_type",
|
|
"ocr_status",
|
|
"created_at",
|
|
]
|
|
readonly_fields = [
|
|
"file_size",
|
|
"content_type",
|
|
"created_at",
|
|
]
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request)
|
|
|
|
|
|
@admin.register(Submission)
|
|
class SubmissionAdmin(admin.ModelAdmin):
|
|
list_display = ["id_short", "game", "user", "notes_preview", "created_at"]
|
|
list_filter = ["game", "created_at", "updated_at"]
|
|
search_fields = ["id", "user__email", "notes", "game__name"]
|
|
readonly_fields = ["id", "created_at", "updated_at"]
|
|
inlines = [SubmissionFileInline]
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related("user", "game")
|
|
|
|
@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_status",
|
|
"created_at",
|
|
]
|
|
list_filter = ["content_type", "ocr_status", "created_at"]
|
|
search_fields = ["original_filename", "submission__id"]
|
|
readonly_fields = ["file_size", "content_type", "created_at", "updated_at"]
|
|
inlines = [ImageCropInline]
|
|
|
|
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]
|
|
|
|
|
|
@admin.register(ImageCrop)
|
|
class ImageCropAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"label_or_coords",
|
|
"file_name",
|
|
"ocr_status",
|
|
"created_at",
|
|
]
|
|
list_filter = ["ocr_status", "created_at"]
|
|
search_fields = ["label", "submission_file__original_filename"]
|
|
readonly_fields = ["created_at", "updated_at"]
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related("submission_file")
|
|
|
|
@admin.display(description="Crop")
|
|
def label_or_coords(self, obj):
|
|
return obj.label or f"({obj.x1}, {obj.y1}, {obj.x2}, {obj.y2})"
|
|
|
|
@admin.display(description="File")
|
|
def file_name(self, obj):
|
|
return obj.submission_file.original_filename
|