django-guardian creates AnonymousUser by default, it does not need a Tenant since it's not used by users
Some tests will fail since they rely on this user's tenant, which is not desirable.
[ ] Fix save() method
[ ] Fix tests
CustomUser model could look like this
class CustomUser(AbstractUser):
tenant = models.ForeignKey(
Tenant, on_delete=models.CASCADE, null=True, blank=True, related_name="users", verbose_name="Организация"
)
class Meta:
indexes = [
models.Index(fields=["tenant"]),
]
def save(self, *args, **kwargs): # type: ignore
if not self.tenant and self.username != "AnonymousUser":
self.tenant = Tenant.objects.create(name=self.email)
# django-guardian creates AnonymousUser by default, it does not need a Tenant since it's not used by users
elif self.username == "AnonymousUser":
self.tenant = None
super().save(*args, **kwargs)
django-guardian creates AnonymousUser by default, it does not need a Tenant since it's not used by users Some tests will fail since they rely on this user's tenant, which is not desirable.
CustomUser model could look like this