from django.db import models

# Create your models here.

class Airport(models.Model):
    code = models.CharField(max_length=3)
    city = models.CharField(max_length=20)

    def __str__(self):
        return f"{self.city}, {self.code}"

class Flight(models.Model):
    origin = models.ForeignKey(Airport, on_delete=models.CASCADE)
    destination = models.CharField(max_length=64)
    duartion = models.IntegerField()

    def __str__(self):
        #return str(self.__dict__)
        return f"{self.id} - {self.origin} to {self.destination}"

class Passenger(models.Model):
    first = models.CharField(max_length=64)
    last = models.CharField(max_length=64)
    flights = models.ManyToManyField(Flight, blank=True, related_name='Passenger')

    def __str__(self):
        return f"{self.first} {self.last}"
