1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

highestGroupNumber

This commit is contained in:
Mo 2022-05-16 18:57:21 +02:00
parent 5627b88051
commit 659156b749

View file

@ -11,6 +11,7 @@ from decimal import ROUND_HALF_UP, Decimal
from flask import flash
from flask_security import current_user
from flask_security.models.fsqla_v2 import FsRoleMixin, FsUserMixin
from sqlalchemy import select
from . import db
from .configUtils import getConfig
@ -170,14 +171,19 @@ class Group(db.Model):
semester = part_students[0].part.semester
program = part_students[0].part.program
groupWithHighestNumber = (
Group.query.filter(Group.semester == semester, Group.program == program)
highestGroupNumber = (
db.session.execute(
select(Group.number)
.where(Group.semester == semester, Group.program == program)
.order_by(Group.number.desc())
.limit(1)
)
.scalars()
.first()
)
if groupWithHighestNumber is not None:
number = groupWithHighestNumber.number + 1
if highestGroupNumber is not None:
number = highestGroupNumber + 1
else:
number = 1