Conversion_Kitchen_Code/kitchen_counter/centralisedFileSystem/admin.py

57 lines
1.7 KiB
Python
Raw Normal View History

2024-04-27 09:33:09 +00:00
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('<a href="{}">{} Scripts</a>', 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('<a href="{}">{} Files</a>', 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"
2024-04-30 04:59:37 +00:00
#@admin.register(BeatSheet)
#class BeatSheetAdmin(admin.ModelAdmin):
# list_display = ("id", "script", "scene_number", "created_on", "modified_on")