diff options
author | CruiseDevice | 2020-07-28 15:56:24 +0530 |
---|---|---|
committer | CruiseDevice | 2020-07-28 15:56:24 +0530 |
commit | 4ab63184215475baf0940a1ab04d8fb990181e20 (patch) | |
tree | 48a97732306ea880630eab8fb74fd39b476b4b33 | |
parent | 856bea5f271e7b83b9d88d539a04a29b507c2b14 (diff) | |
download | workshop_booking-4ab63184215475baf0940a1ab04d8fb990181e20.tar.gz workshop_booking-4ab63184215475baf0940a1ab04d8fb990181e20.tar.bz2 workshop_booking-4ab63184215475baf0940a1ab04d8fb990181e20.zip |
Add a check if json dump exists
-rw-r--r-- | workshop_app/migrations/0012_auto_20200727_2315.py | 35 |
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): |