Provide consist composition

This commit is contained in:
2025-04-27 18:22:13 +02:00
parent 88d718fa94
commit 85741f090c
4 changed files with 17 additions and 3 deletions

View File

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