Added importation of aerodromes
This commit is contained in:
6073
data/airports.csv
Normal file
6073
data/airports.csv
Normal file
File diff suppressed because it is too large
Load Diff
67664
data/routes.csv
Normal file
67664
data/routes.csv
Normal file
File diff suppressed because it is too large
Load Diff
32
simulator/management/commands/import_airports.py
Normal file
32
simulator/management/commands/import_airports.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import csv
|
||||
from django.core.management.base import BaseCommand
|
||||
from simulator.models import Aerodrome
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Import airports from airports.csv"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
with open(
|
||||
"/home/rbitton/gitea/FlightGrid/data/airports.csv",
|
||||
newline="",
|
||||
encoding="utf-8",
|
||||
) as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
icao = row["ICAO"].strip()
|
||||
if not icao: # skip entries without ICAO
|
||||
continue
|
||||
aerodrome, _ = Aerodrome.objects.update_or_create(
|
||||
icao=icao,
|
||||
defaults={
|
||||
"iata": row["IATA"] or None,
|
||||
"name": row["Name"],
|
||||
"city": row["City"],
|
||||
"country": row["Country"],
|
||||
"latitude": float(row["Latitude"]),
|
||||
"longitude": float(row["Longitude"]),
|
||||
"altitude": int(float(row["Altitude"])),
|
||||
},
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS("Import complete"))
|
25
simulator/migrations/0004_route_aerodrome_altitude.py
Normal file
25
simulator/migrations/0004_route_aerodrome_altitude.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 5.2.6 on 2025-10-01 01:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('simulator', '0003_equipment_air_time_hours_equipment_cycles'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Route',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aerodrome',
|
||||
name='altitude',
|
||||
field=models.IntegerField(default=0),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@@ -9,6 +9,7 @@ class Aerodrome(models.Model):
|
||||
country = models.CharField(max_length=3)
|
||||
latitude = models.FloatField()
|
||||
longitude = models.FloatField()
|
||||
altitude = models.IntegerField()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.icao} - {self.city}"
|
||||
|
@@ -132,3 +132,7 @@ class Flight(models.Model):
|
||||
self.equipment.air_time_hours += flight_hours
|
||||
self.equipment.save(update_fields=["cycles", "air_time_hours"])
|
||||
self._stats_updated = True
|
||||
|
||||
|
||||
class Route(models.Model):
|
||||
"""regulary scheduled flights"""
|
||||
|
Reference in New Issue
Block a user