from uuid import UUID from django.contrib import admin from django.urls import reverse from django.utils import html, http, safestring from centralisedFileSystem.models import File, ScreenPlay, Script @admin.register(ScreenPlay) class ScreenPlayAdmin(admin.ModelAdmin): list_display = ("name", "author", "version_count", "created_on", "user", "view_script_links") search_fields = ("name__startswith", "author__startswith") def view_script_links(self, obj : ScreenPlay) -> safestring.SafeText: count = obj.scripts.count() url = ( reverse("admin:centralisedFileSystem_script_changelist") + "?" + http.urlencode({"screenplay__id": f"{obj.id}"}) ) return html.format_html('{} Scripts', url, count) view_script_links.short_description = "Scripts" @admin.register(Script) class ScriptAdmin(admin.ModelAdmin): list_display = ("id", "screenplay", "version", "created_on", "modified_on", "no_of_pages","view_file_links") def view_file_links(self, obj : Script) -> safestring.SafeText: count = obj.scripts_files.count() url = ( reverse("admin:centralisedFileSystem_file_changelist") + "?" + http.urlencode({"script__id": f"{obj.id}"}) ) return html.format_html('{} Files', url, count) view_file_links.short_description = "Files" @admin.register(File) class FileAdmin(admin.ModelAdmin): list_display = ("script_id", "script", "type", "content_type", "modification_id", "modified_on") list_filter = ("type",) def script_id(self, obj : File) -> UUID: return obj.script.id script_id.short_description = "Script Id" # @admin.register(BeatSheet) # class BeatSheetAdmin(admin.ModelAdmin): # list_display = ("id", "script", "scene_number", "created_on", "modified_on")