Skip to content

Commit 46f370e

Browse files
committed
dynamically create Site objects
1 parent 72dfb0e commit 46f370e

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

pod/main/apps.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,27 @@
55
from django.apps import AppConfig
66
from django.db.models.signals import post_migrate
77
from django.utils.translation import gettext_lazy as _
8+
from django.conf import settings
89
from django.core.exceptions import ObjectDoesNotExist
910

1011
import json
1112

13+
SITE_ID = getattr(settings, "SITE_ID", 1)
14+
INSTANCE = os.getenv("POD_INSTANCE", "pod")
15+
PORT = os.getenv("POD_PORT", 8000)
16+
17+
def init_site(sender, **kwargs):
18+
from django.contrib.sites.models import Site
19+
20+
domain = f"http://{INSTANCE}.localhost:{PORT}"
21+
Site.objects.update_or_create(
22+
id=settings.SITE_ID,
23+
defaults={
24+
"domain": domain,
25+
"name": domain,
26+
}
27+
)
28+
1229

1330
def create_missing_pages(sender, **kwargs) -> None:
1431
"""Create missing flat pages from json fixtures."""
@@ -160,3 +177,4 @@ def ready(self):
160177
post_migrate.connect(create_missing_conf, sender=self)
161178
post_migrate.connect(create_missing_pages, sender=self)
162179
post_migrate.connect(create_first_block, sender=self)
180+
post_migrate.connect(init_site, sender=self)

pod/main/fixtures/initial_data.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
[
2-
{
3-
"model": "sites.site",
4-
"pk": 1,
5-
"fields": {
6-
"domain": "pod.localhost:8000",
7-
"name": "pod.localhost:8000"
8-
}
9-
},
102
{
113
"pk": 1,
124
"model": "main.configuration",

0 commit comments

Comments
 (0)