Skip to content

Commit

Permalink
Task: Economic Regions Table Data #381 (#396)
Browse files Browse the repository at this point in the history
* Migration to add regions table data

* Removing comments

* Removing id insertion and adding unique constraint to name
  • Loading branch information
JulianForeman authored Oct 7, 2024
1 parent d1da212 commit 113996b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions django/api/migrations/0038_addregions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.db import migrations, models
from datetime import datetime

def add_region_data(apps, schema_editor):
Regions = apps.get_model('api', 'Regions')

current_timestamp = datetime.now()

regions_data = [
{"name": "Nechako"},
{"name": "Northeast"},
{"name": "Cariboo"},
{"name": "North Coast"},
{"name": "Vancouver Island/Coast"},
{"name": "Mainland/Southwest"},
{"name": "Thompson/Okanagan"},
{"name": "Kootenay"},
{"name": "Across BC"},
]

for region in regions_data:
Regions.objects.get_or_create(
defaults={
"create_timestamp": current_timestamp,
"create_user": "SYSTEM",
"update_timestamp": current_timestamp,
"update_user": "SYSTEM",
"name": region["name"]
}
)

class Migration(migrations.Migration):

dependencies = [
('api', '0037_auto_20240911_1800'),
]

operations = [
migrations.AlterField(
model_name='regions',
name='name',
field=models.CharField(max_length=250, null=False, unique=True)
),
migrations.RunPython(add_region_data),
]

0 comments on commit 113996b

Please sign in to comment.