feat: add django-channel and daphne
This commit is contained in:
@@ -1,5 +1,20 @@
|
||||
from django.contrib import admin
|
||||
from .models import Submission, SubmissionFile
|
||||
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):
|
||||
@@ -9,15 +24,12 @@ class SubmissionFileInline(admin.TabularInline):
|
||||
"original_filename",
|
||||
"file_size",
|
||||
"content_type",
|
||||
"ocr_processed",
|
||||
"ocr_error",
|
||||
"ocr_status",
|
||||
"created_at",
|
||||
]
|
||||
readonly_fields = [
|
||||
"file_size",
|
||||
"content_type",
|
||||
"ocr_processed",
|
||||
"ocr_error",
|
||||
"created_at",
|
||||
]
|
||||
|
||||
@@ -54,12 +66,13 @@ class SubmissionFileAdmin(admin.ModelAdmin):
|
||||
"submission_id",
|
||||
"file_size",
|
||||
"content_type",
|
||||
"ocr_processed",
|
||||
"ocr_status",
|
||||
"created_at",
|
||||
]
|
||||
list_filter = ["content_type", "ocr_processed", "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")
|
||||
@@ -67,3 +80,27 @@ class SubmissionFileAdmin(admin.ModelAdmin):
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user