Docker Image and first iteration
This commit is contained in:
1 parent
723b64b1c4
commit
bd9209ebb7
40 files changed
+26643
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def seed_regions(apps, schema_editor):
|
||||
region_model = apps.get_model("showcase", "Region")
|
||||
seed_path = Path(__file__).with_name("regions.json")
|
||||
regions = json.loads(seed_path.read_text())
|
||||
|
||||
for region in regions["countries"]:
|
||||
region_model.objects.update_or_create(
|
||||
code=region["code"],
|
||||
defaults={"name": region["name"], "level": "country", "parent": None},
|
||||
)
|
||||
|
||||
for region in regions["subdivisions"]:
|
||||
region_model.objects.update_or_create(
|
||||
code=region["code"],
|
||||
defaults={
|
||||
"name": region["name"],
|
||||
"level": "subdivision",
|
||||
"parent_id": region["parentCode"],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def unseed_regions(apps, schema_editor):
|
||||
apps.get_model("showcase", "Region").objects.all().delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("showcase", "0001_initial")]
|
||||
|
||||
operations = [migrations.RunPython(seed_regions, unseed_regions)]
|
||||
|
||||
Reference in new issue
Block a user