Initial subdomain implementation
This commit is contained in:
parent
dea24f7f71
commit
1628e63084
17 changed files with 194 additions and 46 deletions
36
judge/migrations/0145_alter_organization_slug.py
Normal file
36
judge/migrations/0145_alter_organization_slug.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Generated by Django 3.2.16 on 2023-01-23 23:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def make_slug_unique(apps, schema_editor):
|
||||
Organization = apps.get_model("judge", "Organization")
|
||||
slugs = Organization.objects.values_list("slug", flat=True)
|
||||
slugs = set([i.lower() for i in slugs])
|
||||
for slug in slugs:
|
||||
orgs = Organization.objects.filter(slug=slug)
|
||||
if len(orgs) > 1:
|
||||
for org in orgs:
|
||||
org.slug += "-" + str(org.id)
|
||||
org.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("judge", "0144_auto_20230103_0523"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(make_slug_unique, migrations.RunPython.noop, atomic=True),
|
||||
migrations.AlterField(
|
||||
model_name="organization",
|
||||
name="slug",
|
||||
field=models.SlugField(
|
||||
help_text="Organization name shown in URL",
|
||||
max_length=128,
|
||||
unique=True,
|
||||
verbose_name="organization slug",
|
||||
),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue