from django.db import models from .places import Nationality, ZipPlaces, Country, Airport, PhoneCode from .competences import Competence, Role class Address(models.Model): address = models.TextField() zipplace = models.ForeignKey(ZipPlaces, models.PROTECT) class CrewMember(models.Model): pin = models.IntegerField(primary_key=True) first_name = models.CharField(max_length=128) middle_name = models.CharField(max_length=128, null=True, blank=True) last_name = models.CharField(max_length=128) calling_name = models.CharField(max_length=128, null=True, blank=True) suffix_name = models.CharField(max_length=128, null=True, blank=True) title = models.CharField(max_length=128, null=True, blank=True) initials = models.CharField(max_length=16, null=True, blank=True) nationality = models.ForeignKey(Nationality, models.PROTECT) place_of_birth = models.CharField(max_length=128) country_of_birth = models.ForeignKey(Country, models.PROTECT) first_address = models.ForeignKey(Address, models.PROTECT, related_name="crew_first") second_address = models.ForeignKey(Address, models.PROTECT, null=True, related_name="crew_second") closest_airport = models.ForeignKey(Airport, models.PROTECT, related_name="crew_first") second_airport = models.ForeignKey(Airport, models.PROTECT, null=True, related_name="crew_second") roles = models.ManyToManyField(Role, null=True) competences = models.ManyToManyField(Competence, null=True) @property def all_competences(self): return self.competences.all().union(*[role.competences.all() for role in self.roles.all()]) class Phone(models.Model): crew = models.ForeignKey(CrewMember, models.CASCADE) idc = models.ForeignKey(PhoneCode, models.PROTECT, null=True) number = models.CharField(max_length=128) confirmed = models.BooleanField(default=True) priority = models.IntegerField(default=0) class Email(models.Model): crew = models.ForeignKey(CrewMember, models.CASCADE) email = models.EmailField() confirmed = models.BooleanField(default=True) priority = models.IntegerField(default=0)