mirror of
https://github.com/AmanTahiliani/PeerNotes.git
synced 2026-08-07 11:55:12 -04:00
39 lines
827 B
Python
39 lines
827 B
Python
# Generated by Django 4.2.11 on 2024-04-21 03:17
|
|
|
|
from django.db import migrations
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
def load_data_from_json(apps, schema_editor):
|
|
Course = apps.get_model("api", "Course")
|
|
json_file = os.path.abspath(
|
|
os.path.join(
|
|
os.path.dirname(__file__), "..", "utils", "JSON_inputs", "courses.json"
|
|
)
|
|
)
|
|
|
|
with open(json_file, "r") as f:
|
|
data = json.load(f)
|
|
|
|
for item in data:
|
|
try:
|
|
Course.objects.create(
|
|
name=item["name"],
|
|
number=item["number"],
|
|
)
|
|
except Exception as e:
|
|
print("Error:", str(e))
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("api", "0008_userreport"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(load_data_from_json),
|
|
]
|