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