From 7656aa8b68c2bddbbb1d6b5a66e48bdffd093abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Mon, 5 Jan 2026 15:38:51 +0100 Subject: [PATCH] Simplify consist cards cover generator --- ram/consist/models.py | 9 +++++++++ ram/portal/templates/cards/consist.html | 11 ++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ram/consist/models.py b/ram/consist/models.py index 157bb5d..e711bb1 100644 --- a/ram/consist/models.py +++ b/ram/consist/models.py @@ -56,6 +56,15 @@ class Consist(BaseModel): order=models.Max("order"), ).order_by("order") + def get_cover(self): + if self.image: + return self.image + else: + consist_item = self.consist_item.first() + if consist_item and consist_item.rolling_stock.image.exists(): + return consist_item.rolling_stock.image.first().image + return None + @property def country(self): return self.company.country diff --git a/ram/portal/templates/cards/consist.html b/ram/portal/templates/cards/consist.html index 4c5b46e..626fb7a 100644 --- a/ram/portal/templates/cards/consist.html +++ b/ram/portal/templates/cards/consist.html @@ -1,12 +1,13 @@ +{% load static %} +