Fix flask model initialization

This fixes Records and RecordVersions to populate parent objects as part of
the initialization
This commit is contained in:
jokajak 2016-04-24 12:17:22 -04:00
parent 3574eacb25
commit e4e4de7c1d

View File

@ -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
# ------------------------------------------------------------------------------