fixed typo
This commit is contained in:
@@ -28,6 +28,7 @@ class Flight(models.Model):
|
||||
validators=[MinValueValidator(1), MaxValueValidator(9999)]
|
||||
)
|
||||
departure_time = models.DateTimeField()
|
||||
canceled = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
@@ -59,11 +60,9 @@ class Flight(models.Model):
|
||||
return self.departure_time + self.duration
|
||||
|
||||
def clean(self):
|
||||
# Validate origin and destination are different
|
||||
if self.origin == self.destination:
|
||||
raise ValidationError("Origin and destination airports cannot be the same.")
|
||||
|
||||
# Validate carrier owns the equipment
|
||||
if self.equipment.owner != self.carrier:
|
||||
raise ValidationError(
|
||||
f"{self.equipment} is owned by {self.equipment.owner}, "
|
||||
@@ -76,14 +75,18 @@ class Flight(models.Model):
|
||||
f"maximum range ({self.equipment.model.range_nm} nm)."
|
||||
)
|
||||
|
||||
previous_flight = (
|
||||
Flight.objects.filter(
|
||||
equipment=self.equipment, departure_time__lt=self.departure_time
|
||||
)
|
||||
.order_by("-departure_time")
|
||||
.exclude(pk=self.pk)
|
||||
.first()
|
||||
)
|
||||
previous_flights = Flight.objects.filter(
|
||||
equipment=self.equipment,
|
||||
departure_time__lt=self.departure_time,
|
||||
canceled=False,
|
||||
).exclude(pk=self.pk)
|
||||
|
||||
previous_flight = None
|
||||
latest_arrival = None
|
||||
for flight in previous_flights:
|
||||
if latest_arrival is None or flight.arrival_time > latest_arrival:
|
||||
latest_arrival = flight.arrival_time
|
||||
previous_flight = flight
|
||||
|
||||
if previous_flight:
|
||||
if previous_flight.destination != self.origin:
|
||||
@@ -112,6 +115,8 @@ class Flight(models.Model):
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
if self.canceled:
|
||||
return "Canceled"
|
||||
now = timezone.now()
|
||||
if now < self.departure_time:
|
||||
return "Scheduled"
|
||||
|
Reference in New Issue
Block a user