summaryrefslogtreecommitdiff
path: root/workshop_app/migrations
diff options
context:
space:
mode:
authorCruiseDevice2020-07-28 15:56:24 +0530
committerCruiseDevice2020-07-28 15:56:24 +0530
commit4ab63184215475baf0940a1ab04d8fb990181e20 (patch)
tree48a97732306ea880630eab8fb74fd39b476b4b33 /workshop_app/migrations
parent856bea5f271e7b83b9d88d539a04a29b507c2b14 (diff)
downloadworkshop_booking-4ab63184215475baf0940a1ab04d8fb990181e20.tar.gz
workshop_booking-4ab63184215475baf0940a1ab04d8fb990181e20.tar.bz2
workshop_booking-4ab63184215475baf0940a1ab04d8fb990181e20.zip
Add a check if json dump exists
Diffstat (limited to 'workshop_app/migrations')
-rw-r--r--workshop_app/migrations/0012_auto_20200727_2315.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/workshop_app/migrations/0012_auto_20200727_2315.py b/workshop_app/migrations/0012_auto_20200727_2315.py
index 8f38d61..35ab979 100644
--- a/workshop_app/migrations/0012_auto_20200727_2315.py
+++ b/workshop_app/migrations/0012_auto_20200727_2315.py
@@ -8,23 +8,24 @@ from django.db import migrations
def load_data(apps, schema_editor):
Workshop = apps.get_model("workshop_app", "Workshop")
cur_dir = os.path.dirname(os.path.abspath(__file__))
- db_json = os.path.join(cur_dir, '../../db.json')
- with open(db_json, encoding='utf-8') as file:
- workshops = json.load(file)
- for workshop in workshops:
- if workshop['model'] == 'workshop_app.proposeworkshopdate':
- _id = workshop['pk']
- coordinator_id = workshop['fields']['proposed_workshop_coordinator']
- date = workshop['fields']['proposed_workshop_date']
- instructor_id = workshop['fields']['proposed_workshop_instructor']
- status = 1
- tnc_accepted = True
- workshop_type_id = workshop['fields']['proposed_workshop_title']
- Workshop.objects.create(coordinator_id=coordinator_id,
- date=date, instructor_id=instructor_id, status=status,
- tnc_accepted=tnc_accepted,
- workshop_type_id=workshop_type_id
- )
+ db_json = os.path.join(cur_dir, 'db.json')
+ if os.path.exists(db_json):
+ with open(db_json, encoding='utf-8') as file:
+ workshops = json.load(file)
+ for workshop in workshops:
+ if workshop['model'] == 'workshop_app.proposeworkshopdate':
+ _id = workshop['pk']
+ coordinator_id = workshop['fields']['proposed_workshop_coordinator']
+ date = workshop['fields']['proposed_workshop_date']
+ instructor_id = workshop['fields']['proposed_workshop_instructor']
+ status = 1
+ tnc_accepted = True
+ workshop_type_id = workshop['fields']['proposed_workshop_title']
+ Workshop.objects.create(coordinator_id=coordinator_id,
+ date=date, instructor_id=instructor_id, status=status,
+ tnc_accepted=tnc_accepted,
+ workshop_type_id=workshop_type_id
+ )
def reverse_load_data(apps, schema_editor):