polymorphic #1
@@ -1,6 +1,5 @@
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
|
|
||||||
@@ -78,9 +77,18 @@ class HourBuildingLegBase(PolymorphicModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
time = models.DurationField(
|
time = models.DurationField(
|
||||||
null=False
|
null=False,
|
||||||
|
blank=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Change displayed name in the inline form
|
||||||
|
class Meta(PolymorphicModel.Meta):
|
||||||
|
verbose_name = "Flight Leg or Stop"
|
||||||
|
verbose_name_plural = "Flight Legs or Stops"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Hour Building Leg"
|
||||||
|
|
||||||
class HourBuildingLegFlight(HourBuildingLegBase):
|
class HourBuildingLegFlight(HourBuildingLegBase):
|
||||||
departure = models.CharField(
|
departure = models.CharField(
|
||||||
null=False,
|
null=False,
|
||||||
@@ -102,7 +110,7 @@ class HourBuildingLegFlight(HourBuildingLegBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Change displayed name in the inline form
|
# Change displayed name in the inline form
|
||||||
class Meta(PolymorphicModel.Meta):
|
class Meta(HourBuildingLegBase.Meta):
|
||||||
verbose_name = "Flight leg"
|
verbose_name = "Flight leg"
|
||||||
verbose_name_plural = "Flight legs"
|
verbose_name_plural = "Flight legs"
|
||||||
|
|
||||||
@@ -110,8 +118,8 @@ class HourBuildingLegFlight(HourBuildingLegBase):
|
|||||||
return f"{self.departure} -> {self.destination}"
|
return f"{self.departure} -> {self.destination}"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.departure = self.departure.capitalize().strip()
|
self.departure = self.departure.upper().strip()
|
||||||
self.destination = self.destination.capitalize().strip()
|
self.destination = self.destination.upper().strip()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
class HourBuildingLegStop(HourBuildingLegBase):
|
class HourBuildingLegStop(HourBuildingLegBase):
|
||||||
@@ -121,7 +129,7 @@ class HourBuildingLegStop(HourBuildingLegBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Change displayed name in the inline form
|
# Change displayed name in the inline form
|
||||||
class Meta(PolymorphicModel.Meta):
|
class Meta(HourBuildingLegBase.Meta):
|
||||||
verbose_name = "Stop"
|
verbose_name = "Stop"
|
||||||
verbose_name_plural = "Stops"
|
verbose_name_plural = "Stops"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user