class RoleAssignment(models.Model): id = PrimaryKeyUUIDField() role = TreeForeignKey( "people.Role", on_delete=models.CASCADE, related_name="role_assignments", verbose_name=_("role"), ) person = models.ForeignKey( "people.Person", on_delete=models.CASCADE, related_name="role_assignments", verbose_name=_("person"), ) period = DateRangeField(verbose_name=_("period")) trial = models.BooleanField() legacy_table = models.CharField(max_length=64, blank=True) legacy_start_id = models.CharField(max_length=64, blank=True) legacy_end_id = models.CharField(max_length=64, blank=True) class Meta: ordering = ["period"] def __str__(self): return f"{self.person.short_name}: {self.role} ({self.period.lower}–{self.period.upper})"
class Purchase(models.Model): id = PrimaryKeyUUIDField() uid = models.UUIDField( unique=True, default=uuid.uuid1, help_text=_( 'Unique ID used to ensure that offline clients can sync multiple ' 'times without creating duplicates. Offline clients *must* supply ' 'this.', ), ) timestamp = models.DateTimeField(default=now, editable=False, verbose_name=_('timestamp')) person = models.ForeignKey('people.Person', on_delete=models.CASCADE, verbose_name=_('person')) product = models.ForeignKey( 'commerce.Product', on_delete=models.CASCADE, verbose_name=_('product') ) quantity = models.IntegerField(default=1, verbose_name=_('quantity')) sale_point = models.ForeignKey( 'commerce.SalePoint', on_delete=models.CASCADE, verbose_name=_('sale point') ) class Meta: ordering = ('-timestamp', ) verbose_name = _('purchase') verbose_name_plural = _('purchases')
class Person(models.Model): id = PrimaryKeyUUIDField() first_name = NameField(verbose_name=_("first name")) last_name = NameField(verbose_name=_("last name")) nickname = NameField(blank=True, verbose_name=_("nickname")) date_of_birth = models.DateField(null=True, blank=True, verbose_name=_("date of birth")) date_of_death = models.DateField(null=True, blank=True, verbose_name=_("date of death")) # Email must be unique if set email = UniqueEmailField() legacy_id = models.PositiveIntegerField(null=True, blank=True) temp_tour18 = models.BooleanField(default=False) class Meta: ordering = ("first_name", "last_name") def __str__(self): return self.full_name @property def full_name(self): return (f'{self.first_name} "{self.nickname}" {self.last_name}' if self.nickname else f"{self.first_name} {self.last_name}") @property def short_name(self): return self.nickname or f"{self.first_name} {self.last_name[:1]}"
class SalePoint(models.Model): id = PrimaryKeyUUIDField() name = NameField() description = DescriptionField() def __str__(self): return self.name
class Product(models.Model): id = PrimaryKeyUUIDField() name = NameField() description = DescriptionField() price = MoneyDecimalField(null=True, blank=True) def __str__(self): return self.name
class UserAccount(AbstractBaseUser, PermissionsMixin, models.Model): id = PrimaryKeyUUIDField() person = models.OneToOneField( "people.Person", related_name="user_account", on_delete=models.CASCADE, verbose_name=_("person"), ) username = models.CharField( max_length=256, unique=True, validators=[UnicodeUsernameValidator()], verbose_name=_("username"), ) is_active = models.BooleanField(default=True, verbose_name=_("is active")) is_staff = models.BooleanField(default=False, verbose_name=_("is staff")) objects = UserAccountManager() USERNAME_FIELD = "username" REQUIRED_FIELDS = ["person"] def __str__(self): return str(self.person) def save(self, *args, **kwargs): assert self.person.email super().save(*args, **kwargs) @property def email(self): # Having this available on the user model makes some third-party apps # less sad. return self.person.email def get_username(self): return self.username def get_full_name(self): return self.person.full_name def get_short_name(self): return self.person.short_name
class UserAccount(AbstractBaseUser, PermissionsMixin, models.Model): id = PrimaryKeyUUIDField() person = models.OneToOneField( 'people.Person', related_name='user_account', on_delete=models.CASCADE, verbose_name=_('person'), ) username = models.CharField( max_length=256, unique=True, validators=[UnicodeUsernameValidator()], verbose_name=_('username'), ) is_active = models.BooleanField( default=True, verbose_name=_('is active'), ) is_staff = models.BooleanField( default=False, verbose_name=_('is staff'), ) objects = UserAccountManager() USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['person'] def __str__(self): return str(self.person) def save(self, *args, **kwargs): assert self.person.email super().save(*args, **kwargs) def get_username(self): return self.username def get_full_name(self): return self.person.full_name def get_short_name(self): return self.person.short_name
class Person(models.Model): id = PrimaryKeyUUIDField() first_name = NameField(verbose_name=_('first name')) last_name = NameField(verbose_name=_('last name')) nickname = NameField(blank=True, verbose_name=_('nickname')) date_of_birth = models.DateField( null=True, blank=True, verbose_name=_('date of birth'), ) date_of_death = models.DateField( null=True, blank=True, verbose_name=_('date of death'), ) # Email must be unique if set email = UniqueEmailField() legacy_id = models.PositiveIntegerField(null=True, blank=True) temp_tour18 = models.BooleanField(default=False) class Meta: ordering = ('first_name', 'last_name') def __str__(self): return self.full_name def save(self, *args, **kwargs): self.full_clean() super().save(*args, **kwargs) @property def full_name(self): return (f'{self.first_name} "{self.nickname}" {self.last_name}' if self.nickname else f'{self.first_name} {self.last_name}') @property def short_name(self): return self.nickname or f'{self.first_name} {self.last_name[:1]}'
class ServiceAccount(models.Model): id = PrimaryKeyUUIDField() token = models.CharField(max_length=AUTH_TOKEN_LENGTH, editable=False) name = NameField() description = DescriptionField() def save(self, *args, **kwargs): if not self.token: self.token = hex_string(length=AUTH_TOKEN_LENGTH) super().save(*args, **kwargs) @property def is_anonymous(self): return False @property def is_authenticated(self): return True
class Purchase(models.Model): id = PrimaryKeyUUIDField() uid = models.UUIDField( unique=True, default=uuid.uuid1, help_text=_( "Unique ID used to ensure that offline clients can sync multiple " "times without creating duplicates. Offline clients *must* supply " "this."), ) timestamp = models.DateTimeField(default=now, editable=False, verbose_name=_("timestamp")) person = models.ForeignKey( "people.Person", on_delete=models.CASCADE, related_name="purchases", verbose_name=_("person"), ) product = models.ForeignKey( "commerce.Product", on_delete=models.CASCADE, related_name="purchases", verbose_name=_("product"), ) quantity = models.IntegerField(default=1, verbose_name=_("quantity")) sale_point = models.ForeignKey( "commerce.SalePoint", on_delete=models.CASCADE, related_name="purchases", verbose_name=_("sale point"), ) class Meta: ordering = ("-timestamp", ) verbose_name = _("purchase") verbose_name_plural = _("purchases")
class Role(MPTTModel, models.Model): id = PrimaryKeyUUIDField() name = NameField() description = DescriptionField() parent = TreeForeignKey("self", on_delete=models.CASCADE, related_name="children", null=True, blank=True) membership = models.BooleanField(default=False) engagement = models.BooleanField(default=False) legacy_table = models.CharField(max_length=64, blank=True) legacy_id = models.CharField(max_length=64, blank=True) class MPTTMeta: order_insertion_by = ["name"] def __str__(self): return self.name