Ejemplo n.º 1
0
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]}"
Ejemplo n.º 2
0
class SalePoint(models.Model):
    id = PrimaryKeyUUIDField()

    name = NameField()
    description = DescriptionField()

    def __str__(self):
        return self.name
Ejemplo n.º 3
0
class Product(models.Model):
    id = PrimaryKeyUUIDField()

    name = NameField()
    description = DescriptionField()

    price = MoneyDecimalField(null=True, blank=True)

    def __str__(self):
        return self.name
Ejemplo n.º 4
0
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]}'
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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