Skip to content

models

django_spire.api.models

ApiAccess

Bases: ActivityMixin, HistoryModelMixin

name = models.CharField(max_length=128) class-attribute instance-attribute

hashed_key = models.CharField(max_length=128, editable=False) class-attribute instance-attribute

key_hint = models.CharField(max_length=16, editable=False) class-attribute instance-attribute

permission = models.PositiveSmallIntegerField(default=ApiPermissionChoices.VIEW, choices=ApiPermissionChoices) class-attribute instance-attribute

user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='api_access', related_query_name='api_access', null=True, blank=True) class-attribute instance-attribute

objects = ApiAccessQuerySet.as_manager() class-attribute instance-attribute

Meta

verbose_name = 'API Access' class-attribute instance-attribute
verbose_name_plural = 'API Accesses' class-attribute instance-attribute
db_table = 'django_spire_api_access' class-attribute instance-attribute
ordering = ('name',) class-attribute instance-attribute

__str__

Source code in django_spire/api/models.py
def __str__(self) -> str:
    return f'{self.name} - {self.key_hint}'

set_key_and_save

Source code in django_spire/api/models.py
def set_key_and_save(self, raw_key: str) -> None:
    self.hashed_key = hash_string(raw_key)
    self.key_hint = raw_key[:4] + ' ... ' + raw_key[-4:]
    self.save()