tidy up table image dlocks
This commit is contained in:
+3
-14
@@ -1,6 +1,8 @@
|
||||
import django_tables2 as tables
|
||||
from django_tables2.utils import A
|
||||
|
||||
from generic.tables import FirstImageColumn
|
||||
|
||||
from .models import Rapid, UserAnswer
|
||||
|
||||
from django.utils.html import format_html
|
||||
@@ -10,19 +12,6 @@ from easy_thumbnails.files import get_thumbnailer
|
||||
from easy_thumbnails.exceptions import InvalidImageFormatError
|
||||
|
||||
|
||||
class ImageColumn(tables.Column):
|
||||
def render(self, value):
|
||||
obj = value.all()
|
||||
|
||||
if not obj:
|
||||
return format_html('<span>No image<span>')
|
||||
|
||||
image_object = obj[0].image
|
||||
try:
|
||||
thumbnailer = get_thumbnailer(image_object)
|
||||
return format_html('<img src="/media/{}" />', thumbnailer["exam-list"])
|
||||
except InvalidImageFormatError:
|
||||
return format_html('<span title="{}">Invalid image url<span>', image_object)
|
||||
|
||||
|
||||
class RapidTable(tables.Table):
|
||||
@@ -42,7 +31,7 @@ class RapidTable(tables.Table):
|
||||
text='Delete',
|
||||
args=[A('pk')],
|
||||
orderable=False)
|
||||
images = ImageColumn("images", orderable=False)
|
||||
images = FirstImageColumn("images", orderable=False)
|
||||
|
||||
exams = tables.ManyToManyColumn(verbose_name="Exams")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user