Updated database model

This commit is contained in:
Vivek Santayana 2022-08-31 01:13:49 +01:00
parent 42534e13a9
commit 713c6beb48

View File

@ -1,27 +1,26 @@
from ..extensions import db from ..extensions import db
from ..tools.models import JsonString
from sqlalchemy_json import MutableJson from sqlalchemy_json import MutableJson
from datetime import datetime from datetime import datetime
from uuid import uuid4 from uuid import uuid4
class Entry(): class Entry(db.Model):
id = db.Column(db.String(36), primary_key=True) id = db.Column(db.String(36), primary_key=True)
timestamp = db.Column(db.DateTime, nullable=False) timestamp = db.Column(db.DateTime, nullable=False)
answers = db.Column(MutableJson, nullable=False) answers = db.Column(JsonString, nullable=False)
result = db.Column(MutableJson, nullable=False) results = db.Column(MutableJson, nullable=False)
def __repr__(self) -> str: return f'Entry with <id {self.id}>.' def __repr__(self) -> str: return f'Entry with <id {self.id}>.'
@property def __init__(self, answers:list, results:dict):
def generate_id(self): raise AttributeError('generate_id is not a readable attribute.') self.id = uuid4().hex
self.timestamp = datetime.utcnow()
self.answers = answers
self.results = results
generate_id.setter def add(self):
def generate_id(self): self.id = uuid4().hex db.session.add(self)
db.session.commit()
@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()