-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.py
More file actions
30 lines (23 loc) · 879 Bytes
/
models.py
File metadata and controls
30 lines (23 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from model_utils.models import TimeStampedModel
from .managers import BaseAPIKeyManager
class BaseAPIKey(TimeStampedModel):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, related_name="%(class)s", on_delete=models.CASCADE
)
name = models.CharField(max_length=256, null=False, blank=False)
encrypted_api_key = models.BinaryField(null=False, blank=False, default=None)
expiry_date = models.DateTimeField(
blank=True,
null=True,
verbose_name=_("Expiry Date"),
help_text=_("The datetime the API Key expires."),
)
objects = BaseAPIKeyManager(api_key_prefix="BA")
class Meta:
abstract = True
class APIKey(BaseAPIKey):
class Meta(BaseAPIKey.Meta):
abstract = False