Updated database model
This commit is contained in:
parent
42534e13a9
commit
713c6beb48
@ -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 <id {self.id}>.'
|
||||
|
||||
@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()
|
||||
def add(self):
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
Loading…
Reference in New Issue
Block a user