From e4e4de7c1de64969d6d7c4a2f3c29b34e5a56fb7 Mon Sep 17 00:00:00 2001 From: jokajak Date: Sun, 24 Apr 2016 12:17:22 -0400 Subject: [PATCH] Fix flask model initialization This fixes Records and RecordVersions to populate parent objects as part of the initialization --- backend/flask/src/clipperz/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/flask/src/clipperz/models.py b/backend/flask/src/clipperz/models.py index 61ca25d..65466b5 100644 --- a/backend/flask/src/clipperz/models.py +++ b/backend/flask/src/clipperz/models.py @@ -87,8 +87,11 @@ class RecordVersion(db.Model): order_by=id, cascade='all,delete')) - def __init__(self): + def __init__(self, record=None): """Initialize a record version.""" + if record: + self.record = record + self.record_id = record.id self.creation_date = datetime.datetime.utcnow() def update(self, someData): @@ -128,8 +131,11 @@ class Record(db.Model): uselist=False, cascade='save-update, merge, delete, delete-orphan') - def __init__(self): + def __init__(self, user=None): """Initialize a record.""" + if user: + self.user_id = user.id + self.version = 1 self.creation_date = datetime.datetime.utcnow() def update(self, data, record_version): @@ -139,10 +145,7 @@ class Record(db.Model): self.api_version = data['version'] self.update_date = datetime.datetime.now() self.current_record_version = record_version - if self.version: - self.version += 1 - else: - self.version = 1 + self.version += 1 # ------------------------------------------------------------------------------