From 9dd538519f65b0b4d7ff074ced12cd8386ffb917 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 1 Jun 2020 22:51:33 +0200 Subject: [PATCH] fixed recipe table image --- cookbook/tables.py | 18 ++++-------------- cookbook/templates/recipes_table.html | 13 ++++++++++++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cookbook/tables.py b/cookbook/tables.py index 68d89fb9..1ee7b941 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -5,22 +5,12 @@ from django_tables2.utils import A # alias for Accessor from .models import * -from django.utils.safestring import mark_safe -from django.templatetags.static import static -class ImageUrlColumn(tables.LinkColumn): +class ImageUrlColumn(tables.Column): def render(self, value): if value.url: - src = value.url - _class = '' - style = 'object-fit: cover;' - - else: - src = static("recipe_no_image.svg") - _class = 'd-none d-lg-block' - style = 'object-fit: inherit;' - - return mark_safe(f'{_(') + return value.url + return None class RecipeTableSmall(tables.Table): @@ -40,7 +30,7 @@ class RecipeTable(tables.Table): name = tables.LinkColumn('view_recipe', args=[A('id')]) all_tags = tables.Column( attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}}) - image = ImageUrlColumn('view_recipe', args=[A('id')]) + image = ImageUrlColumn() class Meta: model = Recipe diff --git a/cookbook/templates/recipes_table.html b/cookbook/templates/recipes_table.html index 228a5018..3c685480 100644 --- a/cookbook/templates/recipes_table.html +++ b/cookbook/templates/recipes_table.html @@ -14,7 +14,18 @@