diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index cd85f8e..7fd4735 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -58,9 +58,7 @@ class SemesterModelView(SecureModelView): flash("This semester already has parts!", "danger") return - for partLabel in getConfig("partsLabels"): - db.session.add(Part(label=partLabel, semester=model)) - db.session.commit() + model.createParts() if is_created: admin.add_link(MenuLink(name=model.label, diff --git a/testDB.py b/testDB.py index 5d8e96b..fc79c0a 100644 --- a/testDB.py +++ b/testDB.py @@ -13,11 +13,11 @@ with app.app_context(): db.session.add(sem1) db.session.add(sem2) - parta1 = Part(label="A/1", semester=sem2) - partb2 = Part(label="B/2", semester=sem2) + sem1.createParts() + sem2.createParts() - db.session.add(parta1) - db.session.add(partb2) + parta1 = sem2.parts[0] + partb2 = sem2.parts[1] student1 = Student(student_number=123, first_name="Mo", last_name="Bit", uni_email="m@test.com") student2 = Student(student_number=1232, first_name="Mo2", last_name="Bit", uni_email="m2@test.com")