This commit is contained in:
Ross
2021-01-21 19:13:19 +00:00
parent 62ef2a0a54
commit d38583180b
2 changed files with 19 additions and 3 deletions
+17 -1
View File
@@ -3,6 +3,21 @@ from django_tables2.utils import A
from .models import Rapid
from django.utils.html import format_html
from easy_thumbnails.files import get_thumbnailer
from easy_thumbnails.exceptions import InvalidImageFormatError
class ImageColumn(tables.Column):
def render(self, value):
try:
thumbnailer = get_thumbnailer(value)
return format_html('<img src="/media/{}" />', thumbnailer["exam-list"])
except InvalidImageFormatError:
return format_html('<span title="{}">Invalid image url<span>', value)
class RapidTable(tables.Table):
edit = tables.LinkColumn('rapids:rapid_update',
@@ -17,10 +32,11 @@ class RapidTable(tables.Table):
text='Clone',
args=[A('pk')],
orderable=False)
image = ImageColumn("image", orderable=False)
class Meta:
model = Rapid
template_name = "django_tables2/bootstrap4.html"
fields = ("normal", "abnormality", "region", "examination",
"laterality", "site", "created_date", "author")
sequence = ("view", )
sequence = ("view", "image")