Ajout relations pour acces aux partitions et groupes via l'ORM

This commit is contained in:
Emmanuel Viennet 2022-02-17 18:13:04 +01:00
parent 7f164b1e1f
commit 1dbb199d2c
2 changed files with 18 additions and 0 deletions

View File

@ -104,6 +104,11 @@ class FormSemestre(db.Model):
lazy=True,
backref=db.backref("formsemestres", lazy=True),
)
partitions = db.relationship(
"Partition",
backref=db.backref("formsemestre", lazy=True),
lazy="dynamic",
)
# Ancien id ScoDoc7 pour les migrations de bases anciennes
# ne pas utiliser après migrate_scodoc7_dept_archives
scodoc7_id = db.Column(db.Text(), nullable=True)

View File

@ -31,6 +31,11 @@ class Partition(db.Model):
show_in_lists = db.Column(
db.Boolean(), nullable=False, default=True, server_default="true"
)
groups = db.relationship(
"GroupDescr",
backref=db.backref("partition", lazy=True),
lazy="dynamic",
)
def __init__(self, **kwargs):
super(Partition, self).__init__(**kwargs)
@ -42,6 +47,9 @@ class Partition(db.Model):
else:
self.numero = 1
def __repr__(self):
return f"""<{self.__class__.__name__} {self.id} "{self.partition_name or '(default)'}">"""
class GroupDescr(db.Model):
"""Description d'un groupe d'une partition"""
@ -55,6 +63,11 @@ class GroupDescr(db.Model):
# "A", "C2", ... (NULL for 'all'):
group_name = db.Column(db.String(GROUPNAME_STR_LEN))
def __repr__(self):
return (
f"""<{self.__class__.__name__} {self.id} "{self.group_name or '(tous)'}">"""
)
group_membership = db.Table(
"group_membership",