First version of flight preference forms
This commit is contained in:
0
techdb/flightslot/__init__.py
Normal file
0
techdb/flightslot/__init__.py
Normal file
15
techdb/flightslot/admin.py
Normal file
15
techdb/flightslot/admin.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Student, StudentAdmin)
|
||||
admin.site.register(MissionProfile)
|
||||
|
||||
class PreferenceInLIne(admin.TabularInline):
|
||||
model = Preference
|
||||
extra = 0
|
||||
|
||||
class WeekPreferenceAdmin(admin.ModelAdmin):
|
||||
inlines = [PreferenceInLIne]
|
||||
|
||||
admin.site.register(WeekPreference, WeekPreferenceAdmin)
|
||||
6
techdb/flightslot/apps.py
Normal file
6
techdb/flightslot/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class FlightslotConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'flightslot'
|
||||
23
techdb/flightslot/migrations/0001_initial.py
Normal file
23
techdb/flightslot/migrations/0001_initial.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.1.2 on 2024-10-19 16:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Student',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('email', models.EmailField(db_index=True, max_length=254)),
|
||||
('name', models.CharField(max_length=32)),
|
||||
('surname', models.CharField(max_length=32)),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,47 @@
|
||||
# Generated by Django 5.1.2 on 2024-10-19 17:49
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.db.models.expressions
|
||||
import django.db.models.functions.datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('flightslot', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='MissionProfile',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('mtype', models.IntegerField(choices=[('OTHER', 'OTHER'), ('HB', 'HB'), ('PPL', 'PPL'), ('IR', 'IR'), ('CPL', 'CPL'), ('FI', 'FI'), ('PC', 'PC'), ('CHK', 'CHK_6M')], default='HB')),
|
||||
('mnum', models.PositiveSmallIntegerField(default=0, null=True)),
|
||||
('duration', models.DurationField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='WeekPreference',
|
||||
fields=[
|
||||
('id', models.BigAutoField(primary_key=True, serialize=False)),
|
||||
('week', models.PositiveSmallIntegerField(db_default=django.db.models.expressions.CombinedExpression(django.db.models.functions.datetime.ExtractWeek(django.db.models.functions.datetime.Now()), '+', models.Value(1)), db_index=True)),
|
||||
('student', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='flightslot.student')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Preference',
|
||||
fields=[
|
||||
('id', models.BigAutoField(primary_key=True, serialize=False)),
|
||||
('monday', models.BooleanField(default=True)),
|
||||
('tuesday', models.BooleanField(default=True)),
|
||||
('wednesday', models.BooleanField(default=True)),
|
||||
('thursday', models.BooleanField(default=True)),
|
||||
('saturday', models.BooleanField(default=True)),
|
||||
('sunday', models.BooleanField(default=True)),
|
||||
('mission', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='flightslot.missionprofile')),
|
||||
('weekpref', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='flightslot.weekpreference')),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.2 on 2024-10-19 17:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('flightslot', '0002_missionprofile_weekpreference_preference'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='missionprofile',
|
||||
name='mtype',
|
||||
field=models.CharField(choices=[('OTHER', 'OTHER'), ('HB', 'HB'), ('PPL', 'PPL'), ('IR', 'IR'), ('CPL', 'CPL'), ('FI', 'FI'), ('PC', 'PC'), ('CHK', 'CHK_6M')], default='HB'),
|
||||
),
|
||||
]
|
||||
0
techdb/flightslot/migrations/__init__.py
Normal file
0
techdb/flightslot/migrations/__init__.py
Normal file
134
techdb/flightslot/models.py
Normal file
134
techdb/flightslot/models.py
Normal file
@@ -0,0 +1,134 @@
|
||||
from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.db.models.functions import Now, ExtractWeek
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
# Create your models here.
|
||||
class StudentAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "surname", "email")
|
||||
list_filter = []
|
||||
|
||||
class Student(models.Model):
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
email = models.EmailField(
|
||||
null=False,
|
||||
db_index=True
|
||||
)
|
||||
|
||||
name = models.CharField(
|
||||
null=False,
|
||||
max_length=32
|
||||
)
|
||||
|
||||
surname = models.CharField(
|
||||
null=False,
|
||||
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
|
||||
)
|
||||
|
||||
week = models.PositiveSmallIntegerField(
|
||||
null=False,
|
||||
db_index=True,
|
||||
db_default=ExtractWeek(Now()) + 1
|
||||
)
|
||||
|
||||
student = models.ForeignKey(
|
||||
Student,
|
||||
null=False,
|
||||
db_index=True,
|
||||
on_delete=models.DO_NOTHING
|
||||
)
|
||||
|
||||
|
||||
class Preference(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
weekpref = models.ForeignKey(
|
||||
WeekPreference,
|
||||
null=False,
|
||||
on_delete=models.DO_NOTHING
|
||||
)
|
||||
|
||||
mission = models.ForeignKey(
|
||||
MissionProfile,
|
||||
null=True,
|
||||
on_delete=models.DO_NOTHING
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
3
techdb/flightslot/tests.py
Normal file
3
techdb/flightslot/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
techdb/flightslot/views.py
Normal file
3
techdb/flightslot/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@@ -38,6 +38,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'catops',
|
||||
'flightslot'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
Reference in New Issue
Block a user