From 1dbb199d2cde9d577b481e0c177322dfead20dd3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 17 Feb 2022 18:13:04 +0100 Subject: [PATCH] Ajout relations pour acces aux partitions et groupes via l'ORM --- app/models/formsemestre.py | 5 +++++ app/models/groups.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index 245142484..a6411f70f 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -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) diff --git a/app/models/groups.py b/app/models/groups.py index 902298ccf..976d465be 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -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",