Implemented Carrier Aerodrome AircraftBase Equipment

This commit is contained in:
2025-09-29 21:12:33 -05:00
parent 0ce297cab0
commit 5b439485e1
11 changed files with 193 additions and 40 deletions

View File

@@ -20,62 +20,63 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-a_(p5k(2sgb(&ryzu9a+0yz_w+gi-z4o=0m7)kexf9k70k=+j$' SECRET_KEY = "django-insecure-a_(p5k(2sgb(&ryzu9a+0yz_w+gi-z4o=0m7)kexf9k70k=+j$"
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ["100.100.200.0"]
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', "django.contrib.admin",
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.staticfiles', "django.contrib.staticfiles",
"simulator",
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', "django.middleware.security.SecurityMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'django.middleware.clickjacking.XFrameOptionsMiddleware', "django.middleware.clickjacking.XFrameOptionsMiddleware",
] ]
ROOT_URLCONF = 'FlightGrid.urls' ROOT_URLCONF = "FlightGrid.urls"
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', "BACKEND": "django.template.backends.django.DjangoTemplates",
'DIRS': [], "DIRS": [],
'APP_DIRS': True, "APP_DIRS": True,
'OPTIONS': { "OPTIONS": {
'context_processors': [ "context_processors": [
'django.template.context_processors.request', "django.template.context_processors.request",
'django.contrib.auth.context_processors.auth', "django.contrib.auth.context_processors.auth",
'django.contrib.messages.context_processors.messages', "django.contrib.messages.context_processors.messages",
], ],
}, },
}, },
] ]
WSGI_APPLICATION = 'FlightGrid.wsgi.application' WSGI_APPLICATION = "FlightGrid.wsgi.application"
# Database # Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases # https://docs.djangoproject.com/en/5.2/ref/settings/#databases
DATABASES = { DATABASES = {
'default': { "default": {
'ENGINE': 'django.db.backends.sqlite3', "ENGINE": "django.db.backends.sqlite3",
'NAME': BASE_DIR / 'db.sqlite3', "NAME": BASE_DIR / "db.sqlite3",
} }
} }
@@ -85,16 +86,16 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
{ {
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
}, },
] ]
@@ -102,9 +103,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/ # https://docs.djangoproject.com/en/5.2/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = "en-us"
TIME_ZONE = 'UTC' TIME_ZONE = "UTC"
USE_I18N = True USE_I18N = True
@@ -114,9 +115,9 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/ # https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = "static/"
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

View File

@@ -2,6 +2,8 @@ asgiref==3.9.2
astroid==3.3.11 astroid==3.3.11
dill==0.4.0 dill==0.4.0
Django==5.2.6 Django==5.2.6
django-stubs==5.2.5
django-stubs-ext==5.2.5
dotenv==0.9.9 dotenv==0.9.9
isort==6.0.1 isort==6.0.1
mccabe==0.7.0 mccabe==0.7.0
@@ -13,4 +15,7 @@ pylint==3.3.8
python-dotenv==1.1.1 python-dotenv==1.1.1
sqlparse==0.5.3 sqlparse==0.5.3
tomlkit==0.13.3 tomlkit==0.13.3
types-PyYAML==6.0.12.20250915
types-requests==2.32.4.20250913
typing_extensions==4.15.0 typing_extensions==4.15.0
urllib3==2.5.0

View File

@@ -1,3 +1,8 @@
from django.contrib import admin from django.contrib import admin
from .models import Carrier, AircraftBase, Equipment, Aerodrome
# Register your models here. # Register your models here.
admin.site.register(Carrier)
admin.site.register(AircraftBase)
admin.site.register(Equipment)
admin.site.register(Aerodrome)

View File

@@ -0,0 +1,56 @@
# Generated by Django 5.2.6 on 2025-09-30 02:02
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Aerodrome',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('icao', models.CharField(max_length=4, unique=True)),
('iata', models.CharField(blank=True, max_length=3, null=True, unique=True)),
('name', models.CharField(max_length=100)),
('city', models.CharField(max_length=100)),
('country', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='AircraftBase',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
('manufacturer', models.CharField(max_length=50)),
('range_nm', models.IntegerField()),
('capacity', models.IntegerField()),
('cruise_speed_kt', models.IntegerField()),
],
),
migrations.CreateModel(
name='Carrier',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('icao', models.CharField(max_length=3, unique=True)),
('iata', models.CharField(max_length=2, unique=True)),
('name', models.CharField(max_length=100, unique=True)),
('country', models.CharField(max_length=30)),
],
),
migrations.CreateModel(
name='Equipment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('registration', models.CharField(max_length=10, unique=True)),
('model', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='aircraft', to='simulator.aircraftbase')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='fleet', to='simulator.carrier')),
],
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.6 on 2025-09-30 02:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('simulator', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='aerodrome',
name='country',
field=models.CharField(max_length=2),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.6 on 2025-09-30 02:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('simulator', '0002_alter_aerodrome_country'),
]
operations = [
migrations.AlterField(
model_name='aerodrome',
name='country',
field=models.CharField(max_length=3),
),
]

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -0,0 +1,3 @@
from .carrier import Carrier
from .aircraft import Equipment, AircraftBase
from .aerodrome import Aerodrome

View File

@@ -0,0 +1,12 @@
from django.db import models
class Aerodrome(models.Model):
icao = models.CharField(max_length=4, unique=True)
iata = models.CharField(max_length=3, unique=True, blank=True, null=True)
name = models.CharField(max_length=100)
city = models.CharField(max_length=100)
country = models.CharField(max_length=3)
def __str__(self):
return f"{self.icao} - {self.city}"

View File

@@ -0,0 +1,23 @@
from django.db import models
class AircraftBase(models.Model):
name = models.CharField(max_length=20)
manufacturer = models.CharField(max_length=50)
range_nm = models.IntegerField()
capacity = models.IntegerField()
cruise_speed_kt = models.IntegerField()
def __str__(self):
return f"{self.manufacturer} {self.name}"
class Equipment(models.Model):
registration = models.CharField(max_length=10, unique=True)
model = models.ForeignKey(
"AircraftBase", on_delete=models.CASCADE, related_name="aircraft"
)
owner = models.ForeignKey("Carrier", on_delete=models.CASCADE, related_name="fleet")
def __str__(self):
return f"{self.registration} ({self.model})"

View File

@@ -0,0 +1,15 @@
from django.db import models
from .aircraft import Equipment
class Carrier(models.Model):
icao = models.CharField(max_length=3, unique=True)
iata = models.CharField(max_length=2, unique=True)
name = models.CharField(max_length=100, unique=True)
country = models.CharField(max_length=3)
def __str__(self) -> str:
return f"{self.name} ({self.icao}/{self.iata})"
def fleet_size(self) -> int:
return Equipment.objects.filter(owner=self).count()