Added Initial Data

This commit is contained in:
2024-04-21 00:11:51 -04:00
parent b9b405fba8
commit 7bf67974f2
5 changed files with 1869 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
# 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),
]

View File

@@ -0,0 +1,37 @@
# Generated by Django 4.2.11 on 2024-04-21 04:01
from django.db import migrations
import os
import json
def load_data_from_json(apps, schema_editor):
Professor = apps.get_model("api", "Professor")
json_file = os.path.abspath(
os.path.join(
os.path.dirname(__file__), "..", "utils", "JSON_inputs", "faculty_list.json"
)
)
with open(json_file, "r") as f:
data = json.load(f)
for item in data:
try:
Professor.objects.create(
name=item["name"],
)
except Exception as e:
print("Error:", str(e))
class Migration(migrations.Migration):
dependencies = [
("api", "0009_add_course_data"),
]
operations = [
migrations.RunPython(load_data_from_json),
]

View File

@@ -0,0 +1,27 @@
from django.db import migrations
import os
import json
def load_data_from_json(apps, schema_editor):
Semester = apps.get_model("api", "Semester")
Semester.objects.all().delete()
for year in range(2015, 2024):
for sem in ["Spring", "Summer", "Fall"]:
try:
Semester.objects.create(
name=f"{sem} {year}",
)
except Exception as e:
print("Error:", str(e))
class Migration(migrations.Migration):
dependencies = [
("api", "0010_add_professors"),
]
operations = [
migrations.RunPython(load_data_from_json),
]