paperless-ngx/src/documents/admin.py

37 lines
1.2 KiB
Python
Raw Normal View History

2015-12-20 19:23:33 +00:00
from django.conf import settings
from django.contrib import admin
2015-12-26 13:21:19 +00:00
from django.templatetags.static import static
2015-12-20 19:23:33 +00:00
from .models import Document
class DocumentAdmin(admin.ModelAdmin):
search_fields = ("sender", "title", "content",)
2015-12-26 13:21:19 +00:00
list_display = ("edit", "created", "sender", "title", "thumbnail", "pdf")
2015-12-20 19:23:33 +00:00
list_filter = ("created", "sender")
save_on_top = True
2015-12-26 13:21:19 +00:00
def edit(self, obj):
return '<img src="{}" width="64" height="64" alt="Edit icon" />'.format(
static("documents/img/edit.png"))
edit.allow_tags = True
2015-12-20 19:23:33 +00:00
def thumbnail(self, obj):
2015-12-21 02:50:33 +00:00
return '<a href="{media}documents/img/{pk:07}.jpg" target="_blank">' \
'<img src="{media}documents/img/{pk:07}.jpg" width="100" />' \
'</a>'.format(media=settings.MEDIA_URL, pk=obj.pk)
2015-12-20 19:23:33 +00:00
thumbnail.allow_tags = True
def pdf(self, obj):
2015-12-26 13:21:19 +00:00
return '<a href="{}documents/pdf/{:07}.pdf">' \
'<img src="{}" width="64" height="64" alt="PDF icon">' \
'</a>'.format(
settings.MEDIA_URL,
obj.pk,
static("documents/img/application-pdf.png")
)
2015-12-20 19:23:33 +00:00
pdf.allow_tags = True
admin.site.register(Document, DocumentAdmin)