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): def get_absolute_url(self):
return reverse("consist", kwargs={"uuid": self.uuid}) 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 @property
def country(self): def country(self):
return self.company.country return self.company.country

View File

@@ -57,7 +57,7 @@
</tr> </tr>
<tr> <tr>
<th scope="row">Length</th> <th scope="row">Length</th>
<td>{{ d.item.consist_item.count }}</td> <td>{{ d.item.length }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -109,7 +109,7 @@
{% endif %} {% endif %}
<tr> <tr>
<th scope="row">Length</th> <th scope="row">Length</th>
<td>{{ data | length }}</td> <td>{{ consist.length }}: {% for t in consist.get_type_count %}{{ t.count }}x {{ t.type }} {{t.category }}{% if not forloop.last %} + {% endif %}{% endfor %}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -1,4 +1,4 @@
from ram.utils import git_suffix from ram.utils import git_suffix
__version__ = "0.17.3" __version__ = "0.17.4"
__version__ += git_suffix(__file__) __version__ += git_suffix(__file__)