-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
d1da212
commit 113996b
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |