Nested WeekPreference view in admin with nested_inline
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.db.models.functions import Now, ExtractWeek
|
||||
from django.http import HttpRequest
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
# Create your models here.
|
||||
@@ -28,45 +29,6 @@ class Student(models.Model):
|
||||
max_length=32
|
||||
)
|
||||
|
||||
|
||||
class MissionType(models.TextChoices):
|
||||
OTHER = "OTHER", _("OTHER")
|
||||
HB = "HB", _("HB")
|
||||
PPL = "PPL", _("PPL")
|
||||
IR = "IR", _("IR")
|
||||
CPL = "CPL", _("CPL")
|
||||
FI = "FI", _("FI")
|
||||
PC = "PC", _("PC")
|
||||
CHK = "CHK", _("CHK_6M")
|
||||
|
||||
class MissionProfile(models.Model):
|
||||
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
mtype = models.CharField(
|
||||
null=False,
|
||||
default=MissionType.HB,
|
||||
choices=MissionType
|
||||
)
|
||||
|
||||
mnum = models.PositiveSmallIntegerField(
|
||||
null=True,
|
||||
default=0
|
||||
)
|
||||
|
||||
duration = models.DurationField(
|
||||
null=False
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
if self.mtype is not MissionType.HB:
|
||||
return f"{self.mtype}_{self.mnum}"
|
||||
|
||||
class MissionProfileAdmin(admin.ModelAdmin):
|
||||
list_display = ("mtype", "mnum")
|
||||
|
||||
class WeekPreference(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
@@ -75,7 +37,8 @@ class WeekPreference(models.Model):
|
||||
week = models.PositiveSmallIntegerField(
|
||||
null=False,
|
||||
db_index=True,
|
||||
db_default=ExtractWeek(Now()) + 1
|
||||
default=ExtractWeek(Now()) + 1,
|
||||
auto_created=True
|
||||
)
|
||||
|
||||
student = models.ForeignKey(
|
||||
@@ -85,8 +48,55 @@ class WeekPreference(models.Model):
|
||||
on_delete=models.DO_NOTHING
|
||||
)
|
||||
|
||||
class MissionType(models.TextChoices):
|
||||
OTHER = "OTHER", _("OTHER")
|
||||
PPL = "PPL", _("PPL")
|
||||
IR = "IR", _("IR")
|
||||
CPL = "CPL", _("CPL")
|
||||
FI = "FI", _("FI")
|
||||
PC = "PC", _("PC")
|
||||
CHK = "CHK", _("CHK_6M")
|
||||
|
||||
class Preference(models.Model):
|
||||
class MissionProfile(models.Model):
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
mtype = models.CharField(
|
||||
null=False,
|
||||
default=MissionType.PPL,
|
||||
choices=MissionType
|
||||
)
|
||||
|
||||
mnum = models.PositiveSmallIntegerField(
|
||||
null=True,
|
||||
default=0
|
||||
)
|
||||
|
||||
duration = models.DurationField(
|
||||
null=False,
|
||||
default=1
|
||||
)
|
||||
|
||||
notes = models.TextField(
|
||||
max_length=140,
|
||||
null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.mtype} {self.mnum}"
|
||||
|
||||
class MissionProfileAdmin(admin.ModelAdmin):
|
||||
list_display = ("mtype", "mnum")
|
||||
|
||||
class AircraftTypes(models.TextChoices):
|
||||
C152 = "C152", _("Cessna 152")
|
||||
P208 = "P208", _("Tecnam P2008")
|
||||
PA28 = "PA28", _("Piper PA28R")
|
||||
C182 = "C182", _("Cessna 182Q")
|
||||
P210 = "P210", _("Tecnam P2010")
|
||||
|
||||
class HourBuilding(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
@@ -94,13 +104,12 @@ class Preference(models.Model):
|
||||
weekpref = models.ForeignKey(
|
||||
WeekPreference,
|
||||
null=False,
|
||||
on_delete=models.DO_NOTHING
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
mission = models.ForeignKey(
|
||||
MissionProfile,
|
||||
null=True,
|
||||
on_delete=models.DO_NOTHING
|
||||
aircraft = models.CharField(
|
||||
null=False,
|
||||
choices=AircraftTypes
|
||||
)
|
||||
|
||||
monday = models.BooleanField(
|
||||
@@ -132,3 +141,93 @@ class Preference(models.Model):
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
notes = models.TextField(
|
||||
max_length=140,
|
||||
null=True
|
||||
)
|
||||
|
||||
class HourBuildingLeg(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
hb = models.ForeignKey(
|
||||
HourBuilding,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
departure = models.CharField(
|
||||
null=False,
|
||||
blank=False,
|
||||
default="LILV",
|
||||
max_length=4
|
||||
)
|
||||
|
||||
destination = models.CharField(
|
||||
null=False,
|
||||
blank=False,
|
||||
default="LILV",
|
||||
max_length=4
|
||||
)
|
||||
|
||||
time = models.DurationField(
|
||||
null=False,
|
||||
default=1
|
||||
)
|
||||
|
||||
stop = models.BooleanField(
|
||||
default=False
|
||||
)
|
||||
|
||||
class Training(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
weekpref = models.ForeignKey(
|
||||
WeekPreference,
|
||||
null=False,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
mission = models.ForeignKey(
|
||||
MissionProfile,
|
||||
null=True,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
saturday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
sunday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
notes = models.TextField(
|
||||
max_length=140,
|
||||
null=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user