Adde Aircraft class and associate students with aircrafts
This commit is contained in:
@@ -5,5 +5,45 @@ class AircraftTypes(models.TextChoices):
|
||||
C152 = "C152", _("Cessna 152")
|
||||
P208 = "P208", _("Tecnam P2008")
|
||||
PA28 = "PA28", _("Piper PA28R")
|
||||
PA34 = "PA34", _("Piper PA34")
|
||||
C182 = "C182", _("Cessna 182Q")
|
||||
P210 = "TWEN", _("Tecnam P2010")
|
||||
ALX40 = "FSTD", _("Alsim ALX40")
|
||||
|
||||
class Aircraft(models.Model):
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
type = models.CharField(
|
||||
null=False,
|
||||
blank=False,
|
||||
max_length=4, # ICAO naming of aircraft,
|
||||
choices=AircraftTypes
|
||||
)
|
||||
|
||||
markings = models.CharField(
|
||||
null=False,
|
||||
blank=False,
|
||||
max_length=6
|
||||
)
|
||||
|
||||
complex = models.BooleanField(
|
||||
null=False,
|
||||
default=False
|
||||
)
|
||||
|
||||
avail_hours = models.DurationField(
|
||||
null=True,
|
||||
verbose_name=_("Time until maintenance")
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.type} ({self.markings})"
|
||||
|
||||
# Insert dash between first and rest, I-OASM
|
||||
def save(self, *args, **kwargs):
|
||||
self.markings = self.markings.upper()
|
||||
if not "-" in self.markings:
|
||||
self.markings = self.markings[0] + "-" + self.markings[1:]
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@@ -10,14 +10,18 @@ class CourseTypes(models.TextChoices):
|
||||
DISTANCE = "DL", _("DISTANCE")
|
||||
OTHER = "OTHER",_("OTHER")
|
||||
|
||||
|
||||
class Course(models.Model):
|
||||
# Add colors according to table from Alessia
|
||||
COLOR_PALETTE = [
|
||||
("#ffffff","WHITE"),
|
||||
("#bfbfbf","GREY"),
|
||||
("#ff0000", "RED"),
|
||||
("#00ff00", "GREEN"),
|
||||
("#0000ff", "BLUE")
|
||||
("#ffc000", "ORANGE"),
|
||||
("#ffff00", "YELLOW"),
|
||||
("#92d050", "GREEN"),
|
||||
("#00b0f0", "CYAN"),
|
||||
("#b1a0c7", "MAGENTA"),
|
||||
("#fabcfb", "PINK"),
|
||||
("#f27ae4", "VIOLET"),
|
||||
]
|
||||
|
||||
id = models.AutoField(
|
||||
@@ -43,8 +47,8 @@ class Course(models.Model):
|
||||
)
|
||||
|
||||
color = ColorField (
|
||||
samples=COLOR_PALETTE,
|
||||
verbose_name=_("Binder Color")
|
||||
verbose_name=_("Binder Color"),
|
||||
samples=COLOR_PALETTE
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -2,6 +2,7 @@ from django.db import models
|
||||
from django.contrib.auth.models import User, Group
|
||||
|
||||
from ..models.courses import Course
|
||||
from ..models.aircrafts import Aircraft
|
||||
|
||||
class Student(models.Model):
|
||||
id = models.AutoField(
|
||||
@@ -46,6 +47,10 @@ class Student(models.Model):
|
||||
blank=True
|
||||
)
|
||||
|
||||
aircrafts = models.ManyToManyField(
|
||||
Aircraft
|
||||
)
|
||||
|
||||
def default_password(self) -> str: # Maximum 4 digits for passowrd
|
||||
return f"{self.name.lower()[0]}{self.surname.lower()}{self.id % 10000}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user