Add region object
This commit is contained in:
parent
330f103844
commit
0a1a9ab4d8
2 changed files with 39 additions and 0 deletions
|
|
@ -54,6 +54,12 @@ class Organization(MaintainableObject):
|
|||
org_slug = models.CharField(max_length=300)
|
||||
org_title = models.CharField(max_length=300)
|
||||
region_slug = models.CharField(max_length=300, null=True, default=None)
|
||||
migration_destination = models.ForeignKey(
|
||||
to="user_management.Region",
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="regions",
|
||||
default=None,
|
||||
)
|
||||
|
||||
grafana_url = models.URLField()
|
||||
|
||||
|
|
|
|||
33
engine/apps/user_management/models/region.py
Normal file
33
engine/apps/user_management/models/region.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from django.conf import settings
|
||||
from django.core.validators import MinLengthValidator
|
||||
from django.db import models
|
||||
|
||||
from common.public_primary_keys import generate_public_primary_key, increase_public_primary_key_length
|
||||
|
||||
|
||||
def generate_public_primary_key_for_region():
|
||||
prefix = "R"
|
||||
new_public_primary_key = generate_public_primary_key(prefix)
|
||||
|
||||
failure_counter = 0
|
||||
while Region.objects.filter(public_primary_key=new_public_primary_key).exists():
|
||||
new_public_primary_key = increase_public_primary_key_length(
|
||||
failure_counter=failure_counter, prefix=prefix, model_name="Region"
|
||||
)
|
||||
failure_counter += 1
|
||||
|
||||
return new_public_primary_key
|
||||
|
||||
|
||||
class Region(models.Model):
|
||||
public_primary_key = models.CharField(
|
||||
max_length=20,
|
||||
validators=[MinLengthValidator(settings.PUBLIC_PRIMARY_KEY_MIN_LENGTH + 1)],
|
||||
unique=True,
|
||||
default=generate_public_primary_key_for_region,
|
||||
)
|
||||
|
||||
name = models.CharField(max_length=300)
|
||||
slug = models.CharField(max_length=300, unique=True)
|
||||
oncall_backend_url = models.URLField()
|
||||
is_default = models.BooleanField(default=False)
|
||||
Loading…
Add table
Reference in a new issue