diff --git a/ram/consist/models.py b/ram/consist/models.py index f89b5b9..f9d5ac8 100644 --- a/ram/consist/models.py +++ b/ram/consist/models.py @@ -39,6 +39,20 @@ class Consist(BaseModel): def get_absolute_url(self): return reverse("consist", kwargs={"uuid": self.uuid}) + @property + def length(self): + return self.consist_item.count() + + def get_type_count(self): + return self.consist_item.annotate( + type=models.F("rolling_stock__rolling_class__type__type") + ).values( + "type" + ).annotate( + count=models.Count("rolling_stock"), + category=models.F("rolling_stock__rolling_class__type__category") + ).order_by("rolling_stock__rolling_class__type__order") + @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 d8075c5..7b11d6b 100644 --- a/ram/portal/templates/cards/consist.html +++ b/ram/portal/templates/cards/consist.html @@ -57,7 +57,7 @@ Length - {{ d.item.consist_item.count }} + {{ d.item.length }} diff --git a/ram/portal/templates/consist.html b/ram/portal/templates/consist.html index 254de34..79b85db 100644 --- a/ram/portal/templates/consist.html +++ b/ram/portal/templates/consist.html @@ -109,7 +109,7 @@ {% endif %} Length - {{ data | length }} + {{ consist.length }}: {% for t in consist.get_type_count %}{{ t.count }}x {{ t.type }} {{t.category }}{% if not forloop.last %} + {% endif %}{% endfor %} diff --git a/ram/ram/__init__.py b/ram/ram/__init__.py index c84cd75..21933ee 100644 --- a/ram/ram/__init__.py +++ b/ram/ram/__init__.py @@ -1,4 +1,4 @@ from ram.utils import git_suffix -__version__ = "0.17.3" +__version__ = "0.17.4" __version__ += git_suffix(__file__)