Minor admin improvements and remove unique_together deprecated Meta

Also make rolling stock unique per consist
This commit is contained in:
2025-01-08 23:28:04 +01:00
parent f286ec9780
commit 26be22c0bd
11 changed files with 169 additions and 15 deletions

View File

@@ -54,10 +54,20 @@ class ConsistItem(models.Model):
Consist, on_delete=models.CASCADE, related_name="consist_item"
)
rolling_stock = models.ForeignKey(RollingStock, on_delete=models.CASCADE)
order = models.PositiveIntegerField(default=0, blank=False, null=False)
order = models.PositiveIntegerField(
default=1000, # make sure it is always added at the end
blank=False,
null=False
)
class Meta(object):
class Meta:
ordering = ["order"]
constraints = [
models.UniqueConstraint(
fields=["consist", "rolling_stock"],
name="one_stock_per_consist"
)
]
def __str__(self):
return "{0}".format(self.rolling_stock)