Simplify consist cards cover generator

This commit is contained in:
2026-01-05 15:38:51 +01:00
parent 1be102b9d4
commit 7656aa8b68
2 changed files with 15 additions and 5 deletions

View File

@@ -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

View File

@@ -1,12 +1,13 @@
{% load static %}
<div class="col">
<div class="card shadow-sm">
<a href="{{ d.get_absolute_url }}">
{% if d.image %}
<img class="card-img-top" src="{{ d.image.url }}" alt="{{ d }}">
{% if d.get_cover %}
<img class="card-img-top" src="{{ d.get_cover.url }}" alt="{{ d }}">
{% else %}
{% with d.consist_item.first.rolling_stock as r %}
<img class="card-img-top" src="{{ r.image.first.image.url }}" alt="{{ d }}">
{% endwith %}
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
<a href="{{d.get_absolute_url}}"><img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d }}"></a>
{% endif %}
</a>
<div class="card-body">