Files
Michael Herrmann 6cee5d6cd7 Reformat code
2024-02-01 15:13:40 +01:00

18 lines
596 B
Python

from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Model, UUIDField, ManyToManyField
from uuid import uuid4
class Tenant(Model):
users = ManyToManyField(User)
uuid = UUIDField(unique=True, default=uuid4, editable=False)
def __str__(self):
# We have to check that `id` is set to avoid a `RecursionError`.
if self.id:
try:
return self.users.earliest('date_joined').username
except ObjectDoesNotExist:
pass
return str(self.uuid)