From 5704633d14ad750ab64d1d63a4e00a9287d183b5 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Thu, 8 Sep 2022 00:51:34 +0200 Subject: [PATCH] Save contact_email only if it is different --- advlabdb/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/advlabdb/models.py b/advlabdb/models.py index 47d725c..37a6865 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -60,6 +60,12 @@ class Student(db.Model): part_students = db.relationship("PartStudent", back_populates="student", lazy=True) + def __init__(self, uni_email, contact_email=None, **kwargs): + if contact_email is not None and uni_email.strip() == contact_email.strip(): + contact_email = None + + super().__init__(uni_email=uni_email, contact_email=contact_email, **kwargs) + def str(self): return f"{self.first_name} {self.last_name}"