Skip to content

admin

django_spire.file.admin

FileAdmin

Bases: ModelAdmin

list_display = ('id', 'name', 'type', 'formatted_size', 'content_object_link', 'file_link') class-attribute instance-attribute

list_filter = ('type',) class-attribute instance-attribute

search_fields = ('id', 'name', 'type') class-attribute instance-attribute

ordering = ('-id',) class-attribute instance-attribute

formatted_size

Source code in django_spire/file/admin.py
def formatted_size(self, file: models.File) -> str:
    return file.formatted_size
Source code in django_spire/file/admin.py
def content_object_link(self, file: models.File) -> str:
    if file.content_type is None or file.object_id is None:
        return 'No Related Object'

    content_object = file.content_object

    if content_object is None:
        return 'No Related Object'

    url = reverse(
        f'admin:{file.content_type.app_label}_{file.content_type.model}_change',
        args=[file.object_id]
    )

    return format_html('<a href="{}">{}</a>', url, content_object)
Source code in django_spire/file/admin.py
def file_link(self, file: models.File) -> str:
    return format_html('<a href="{}" download>{}</a>', file.file.url, file.name)