From 713c6beb48efda0b092447228fac1b47e2911d84 Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Wed, 31 Aug 2022 01:13:49 +0100 Subject: [PATCH] Updated database model --- server/app/models/entry.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/server/app/models/entry.py b/server/app/models/entry.py index b9d262b..ea8e6af 100644 --- a/server/app/models/entry.py +++ b/server/app/models/entry.py @@ -1,27 +1,26 @@ from ..extensions import db +from ..tools.models import JsonString from sqlalchemy_json import MutableJson from datetime import datetime from uuid import uuid4 -class Entry(): - +class Entry(db.Model): + id = db.Column(db.String(36), primary_key=True) timestamp = db.Column(db.DateTime, nullable=False) - answers = db.Column(MutableJson, nullable=False) - result = db.Column(MutableJson, nullable=False) + answers = db.Column(JsonString, nullable=False) + results = db.Column(MutableJson, nullable=False) def __repr__(self) -> str: return f'Entry with .' - @property - def generate_id(self): raise AttributeError('generate_id is not a readable attribute.') + def __init__(self, answers:list, results:dict): + self.id = uuid4().hex + self.timestamp = datetime.utcnow() + self.answers = answers + self.results = results - generate_id.setter - def generate_id(self): self.id = uuid4().hex - - @property - def set_timestamp(self): raise AttributeError('set_timestamp is not a readable attribute.') - - set_timestamp.setter - def set_timestamp(self): self.timestamp = datetime.utcnow() \ No newline at end of file + def add(self): + db.session.add(self) + db.session.commit() \ No newline at end of file