expephalon/core/models/api.py

21 lines
No EOL
632 B
Python

from django.db.models import Model, UUIDField, ForeignKey, CASCADE, TextField
from core.models.profiles import AdminProfile
import uuid
class APIKey(Model):
key = UUIDField(default=uuid.uuid4)
admin = ForeignKey(AdminProfile, on_delete=CASCADE)
permission_string = TextField(blank=True, default=[])
@property
def permissions(self):
return self.permission_string.split(",")
@permissions.setter
def permissions(self, permissions):
if isinstance(permissions, str):
self.permission_string = permissions
else:
self.permission_string = ",".join(permissions)