added more flight logic

This commit is contained in:
2025-09-30 18:26:14 -05:00
parent 12bedaf6a8
commit 9493fffff5
3 changed files with 58 additions and 11 deletions

View File

@@ -26,6 +26,15 @@ class Equipment(models.Model):
null=True,
blank=True,
)
cycles = models.PositiveIntegerField(
default=0, help_text="Total number of flight cycles (takeoff/landing pairs)"
)
air_time_hours = models.DecimalField(
max_digits=10,
decimal_places=2,
default=0,
help_text="Total air time in hours",
)
def __str__(self):
return f"{self.registration} ({self.model})"
@@ -38,7 +47,6 @@ class Equipment(models.Model):
now = timezone.now()
# Get the most recent flight relative to now
last_flight = (
self.flights.filter(departure_time__lte=now)
.order_by("-departure_time")
@@ -46,10 +54,8 @@ class Equipment(models.Model):
)
if last_flight:
# Check if plane is currently in flight
if last_flight.departure_time <= now < last_flight.arrival_time:
return "In-Flight"
# Plane has arrived at destination
elif last_flight.arrival_time <= now:
return last_flight.destination