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 %} +
- {% if d.image %} - {{ d }} + {% if d.get_cover %} + {{ d }} {% else %} - {% with d.consist_item.first.rolling_stock as r %} - {{ d }} - {% endwith %} + + {{ d }} {% endif %}