update create groups endpoint - fixing errors when adding students to the group

This commit is contained in:
dominik24c 2022-06-13 21:47:12 +02:00
parent 56853fb906
commit 980cf5da50

View File

@ -60,13 +60,13 @@ def create_group(data: dict) -> dict:
if students_without_groups != len(students_indexes): if students_without_groups != len(students_indexes):
abort(400, "One or more students have already belonged to group!") abort(400, "One or more students have already belonged to group!")
db.session.add(group)
db.session.commit()
students = db.session.query(Student).filter(Student.index.in_(students_indexes)).all() students = db.session.query(Student).filter(Student.index.in_(students_indexes)).all()
project_supervisor.count_groups += 1
for student in students: for student in students:
student.group_id = group.id student.group_id = group.id
db.session.add_all(students)
db.session.add(group)
db.session.commit() db.session.commit()
return {"message": "Project Supervisor was created!"} return {"message": "Project Supervisor was created!"}