Polymorphic model correctly saves, fixed formatting of admin
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -51,7 +51,7 @@ class Student(models.Model):
|
||||
|
||||
# Override save method to add user for login upon Student creation
|
||||
def save(self, *args, **kwargs):
|
||||
creating = self.pk is None
|
||||
creating: bool = self.pk is None
|
||||
super().save(*args, **kwargs)
|
||||
if creating and not self.user:
|
||||
username = f"{self.name.lower()}.{self.surname.lower()}"
|
||||
@@ -68,7 +68,7 @@ class Student(models.Model):
|
||||
username=username,
|
||||
email=self.email,
|
||||
password=self.default_password(),
|
||||
is_staff=True
|
||||
is_staff=True # allows access to admin page
|
||||
)
|
||||
|
||||
student_group, _ = Group.objects.get_or_create(name="StudentGroup")
|
||||
|
||||
Reference in New Issue
Block a user