Skip to content

admin

django_spire.file.admin

FileAdmin

Bases: ModelAdmin

list_display = ('id', 'name', 'type', '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

Source code in django_spire/file/admin.py
def content_object_link(self, file: models.File) -> str:
    if file.content_object:
        url = reverse(
            f'admin:{file.content_type.app_label}_{file.content_type.model}_change',
            args=[file.object_id]
        )

        return format_html(f'<a href="{url}">{file.content_object}</a>')

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