Prettied up the admin

This commit is contained in:
Daniel Quinn 2015-12-26 13:21:19 +00:00
parent b65f9af9cc
commit cb0f7393d6
4 changed files with 15 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from django.conf import settings
from django.contrib import admin
from django.templatetags.static import static
from .models import Document
@ -7,10 +8,15 @@ from .models import Document
class DocumentAdmin(admin.ModelAdmin):
search_fields = ("sender", "title", "content",)
list_display = ("created", "sender", "title", "thumbnail", "pdf")
list_display = ("edit", "created", "sender", "title", "thumbnail", "pdf")
list_filter = ("created", "sender")
save_on_top = True
def edit(self, obj):
return '<img src="{}" width="64" height="64" alt="Edit icon" />'.format(
static("documents/img/edit.png"))
edit.allow_tags = True
def thumbnail(self, obj):
return '<a href="{media}documents/img/{pk:07}.jpg" target="_blank">' \
'<img src="{media}documents/img/{pk:07}.jpg" width="100" />' \
@ -18,8 +24,13 @@ class DocumentAdmin(admin.ModelAdmin):
thumbnail.allow_tags = True
def pdf(self, obj):
return '<a href="{}documents/pdf/{:07}.pdf">Download</a>'.format(
settings.MEDIA_URL, obj.pk)
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")
)
pdf.allow_tags = True
admin.site.register(Document, DocumentAdmin)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -19,5 +19,5 @@ from django.conf.urls import url, static
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', admin.site.urls),
] + static.static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)