This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/attachments/admin.py

50 lines
1.3 KiB
Python
Raw Normal View History

2020-08-26 19:04:48 +02:00
from django.contrib import admin
from django.contrib.admin import register
from django.utils.html import format_html
2020-08-26 19:04:48 +02:00
from attachments.models import Attachment
@register(Attachment)
class AttachmentAdmin(admin.ModelAdmin):
2020-08-28 21:49:15 +02:00
list_display = [
"description",
"original_file",
"original_file_url",
"processed_file",
"processed_file_url",
]
2020-08-26 19:04:48 +02:00
list_display_links = ["description"]
fields = [
"description",
"original_file",
"original_file_url",
"processed_file",
"processed_file_url",
]
readonly_fields = [
"original_file_url",
"processed_file_url",
]
2020-08-28 21:49:15 +02:00
class Media:
js = ["attachments/js/copy_url.js"]
def processed_file_url(self, instance):
2020-08-28 21:58:18 +02:00
if instance.processed_file:
return format_html(
'{} <a class="copy-button" data-to-copy="{}" href="#">&#128203;</a>',
instance.processed_file.url,
instance.processed_file.url,
)
2020-08-28 21:58:18 +02:00
return ""
2020-08-28 21:49:15 +02:00
def original_file_url(self, instance):
2020-08-28 21:58:18 +02:00
if instance.original_file:
return format_html(
'{} <a class="copy-button" data-to-copy="{}" href="#">&#128203;</a>',
instance.original_file.url,
instance.original_file.url,
)
2020-08-28 21:58:18 +02:00
return ""