Add account-scoped access for hosting customers

This commit is contained in:
parkel committed 2026-11-21 00:23:52 +01:00
1 parent 4bbe265915
commit 8de6eb8d88
11 files changed
+390 -51

No files matched your search

+20 -1
View File
@@ -21,7 +21,7 @@ class Reseller(models.Model):
settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
related_name="hosting_reseller",
limit_choices_to={"is_superuser": False},
limit_choices_to={"is_superuser": False, "hosting_customer__isnull": True},
)
account_limit = models.PositiveIntegerField(default=0)
hosting_plans = models.ManyToManyField("HostingPlan", blank=True)
@@ -33,6 +33,22 @@ class Reseller(models.Model):
return self.user.get_username()
class Customer(models.Model):
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
related_name="hosting_customer",
limit_choices_to={
"is_staff": False,
"is_superuser": False,
"hosting_reseller__isnull": True,
},
)
def __str__(self):
return self.user.get_username()
class HostingPlan(models.Model):
name = models.CharField(max_length=120, unique=True)
description = models.CharField(max_length=240, blank=True)
@@ -53,6 +69,9 @@ class HostingAccount(models.Model):
reseller = models.ForeignKey(
Reseller, on_delete=models.PROTECT, null=True, blank=True
)
customer = models.ForeignKey(
Customer, on_delete=models.PROTECT, null=True, blank=True
)
created_at = models.DateTimeField(auto_now_add=True)
def get_absolute_url(self):