138 lines
2.9 KiB
Python
138 lines
2.9 KiB
Python
from django.utils.translation import gettext_lazy as _
|
|
from django.db import models
|
|
|
|
from polymorphic.models import PolymorphicModel
|
|
|
|
from ..models.weekpref import WeekPreference
|
|
from ..models.aircrafts import AircraftTypes
|
|
|
|
class HourBuilding(models.Model):
|
|
id = models.BigAutoField(
|
|
primary_key=True
|
|
)
|
|
|
|
weekpref = models.ForeignKey(
|
|
WeekPreference,
|
|
null=False,
|
|
on_delete=models.CASCADE
|
|
)
|
|
|
|
aircraft = models.CharField(
|
|
null=False,
|
|
choices=AircraftTypes
|
|
)
|
|
|
|
monday = models.BooleanField(
|
|
default=True,
|
|
null=False
|
|
)
|
|
|
|
tuesday = models.BooleanField(
|
|
default=True,
|
|
null=False
|
|
)
|
|
|
|
wednesday = models.BooleanField(
|
|
default=True,
|
|
null=False
|
|
)
|
|
|
|
thursday = models.BooleanField(
|
|
default=True,
|
|
null=False
|
|
)
|
|
|
|
friday = models.BooleanField(
|
|
default=True,
|
|
null=False
|
|
)
|
|
|
|
saturday = models.BooleanField(
|
|
default=True,
|
|
null=False
|
|
)
|
|
|
|
sunday = models.BooleanField(
|
|
default=True,
|
|
null=False
|
|
)
|
|
|
|
notes = models.TextField(
|
|
max_length=140,
|
|
null=True,
|
|
blank=True
|
|
)
|
|
|
|
def __str__(self):
|
|
return f"Hour Building: {self.aircraft}"
|
|
|
|
class HourBuildingLegBase(PolymorphicModel):
|
|
id = models.BigAutoField(
|
|
primary_key=True
|
|
)
|
|
|
|
hb = models.ForeignKey(
|
|
HourBuilding,
|
|
on_delete=models.CASCADE
|
|
)
|
|
|
|
time = models.DurationField(
|
|
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):
|
|
departure = models.CharField(
|
|
null=False,
|
|
blank=False,
|
|
max_length=4
|
|
)
|
|
|
|
destination = models.CharField(
|
|
null=False,
|
|
blank=False,
|
|
max_length=4
|
|
)
|
|
|
|
pax = models.CharField(
|
|
null=True,
|
|
blank=True,
|
|
max_length=16,
|
|
verbose_name="Pax (optional)"
|
|
)
|
|
|
|
# Change displayed name in the inline form
|
|
class Meta(HourBuildingLegBase.Meta):
|
|
verbose_name = "Flight leg"
|
|
verbose_name_plural = "Flight legs"
|
|
|
|
def save(self, *args, **kwargs):
|
|
self.departure = self.departure.upper().strip()
|
|
self.destination = self.destination.upper().strip()
|
|
super().save(*args, **kwargs)
|
|
|
|
def __str__(self):
|
|
return f"{self.departure} -> {self.destination}"
|
|
|
|
class HourBuildingLegStop(HourBuildingLegBase):
|
|
|
|
refuel = models.BooleanField(
|
|
default=False
|
|
)
|
|
|
|
# Change displayed name in the inline form
|
|
class Meta(HourBuildingLegBase.Meta):
|
|
verbose_name = "Stop"
|
|
verbose_name_plural = "Stops"
|
|
|
|
def __str__(self):
|
|
return f"Refuel" if self.refuel else f"No Refuel"
|
|
|