Polymorphic model correctly saves, fixed formatting of admin

This commit is contained in:
2025-11-21 17:49:51 +01:00
parent 02990d4b2f
commit 48ff1d799c
7 changed files with 105 additions and 30 deletions

View File

@@ -78,36 +78,51 @@ class HourBuildingLegBase(PolymorphicModel):
)
time = models.DurationField(
null=False,
default = timedelta(hours=1)
null=False
)
class HourBuildingLegFlight(HourBuildingLegBase):
departure = models.CharField(
null=False,
blank=False,
default="LILV",
max_length=4
)
destination = models.CharField(
null=False,
blank=False,
default="LILV",
max_length=4
)
pax = models.CharField(
null=True,
blank=True,
max_length=16,
verbose_name="Pax (optional)"
)
class Meta(PolymorphicModel.Meta):
verbose_name = "Flight leg"
verbose_name_plural = "Flight legs"
def __str__(self):
return f"Flight Leg: {self.departure} -> {self.destination}"
return f"{self.departure} -> {self.destination}"
def save(self, *args, **kwargs):
self.departure = self.departure.capitalize().strip()
self.destination = self.destination.capitalize().strip()
super().save(*args, **kwargs)
class HourBuildingLegStop(HourBuildingLegBase):
location = models.CharField(
null=False,
blank=False,
default="LILV",
max_length=4
)
refuel = models.BooleanField(
default=False
)
)
class Meta(PolymorphicModel.Meta):
verbose_name = "Stop"
verbose_name_plural = "Stops"
def __str__(self):
return f"Refuel" if self.refuel else f"No Refuel"