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