diff --git a/techdb/flightslot/__init__.py b/techdb/flightslot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/techdb/flightslot/admin.py b/techdb/flightslot/admin.py new file mode 100644 index 0000000..31bfbfa --- /dev/null +++ b/techdb/flightslot/admin.py @@ -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) \ No newline at end of file diff --git a/techdb/flightslot/apps.py b/techdb/flightslot/apps.py new file mode 100644 index 0000000..5031d69 --- /dev/null +++ b/techdb/flightslot/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class FlightslotConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'flightslot' diff --git a/techdb/flightslot/migrations/0001_initial.py b/techdb/flightslot/migrations/0001_initial.py new file mode 100644 index 0000000..ca2e7db --- /dev/null +++ b/techdb/flightslot/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/techdb/flightslot/migrations/0002_missionprofile_weekpreference_preference.py b/techdb/flightslot/migrations/0002_missionprofile_weekpreference_preference.py new file mode 100644 index 0000000..fc94827 --- /dev/null +++ b/techdb/flightslot/migrations/0002_missionprofile_weekpreference_preference.py @@ -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')), + ], + ), + ] diff --git a/techdb/flightslot/migrations/0003_alter_missionprofile_mtype.py b/techdb/flightslot/migrations/0003_alter_missionprofile_mtype.py new file mode 100644 index 0000000..79cf6b6 --- /dev/null +++ b/techdb/flightslot/migrations/0003_alter_missionprofile_mtype.py @@ -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'), + ), + ] diff --git a/techdb/flightslot/migrations/__init__.py b/techdb/flightslot/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/techdb/flightslot/models.py b/techdb/flightslot/models.py new file mode 100644 index 0000000..6c5bc96 --- /dev/null +++ b/techdb/flightslot/models.py @@ -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 + ) diff --git a/techdb/flightslot/tests.py b/techdb/flightslot/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/techdb/flightslot/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/techdb/flightslot/views.py b/techdb/flightslot/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/techdb/flightslot/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/techdb/techdb/settings.py b/techdb/techdb/settings.py index 9a79066..57b6876 100644 --- a/techdb/techdb/settings.py +++ b/techdb/techdb/settings.py @@ -38,6 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'catops', + 'flightslot' ] MIDDLEWARE = [