wanderhome-quiz/server/app/models/entry.py

27 lines
805 B
Python

from ..extensions import db
from sqlalchemy_json import MutableJson
from datetime import datetime
from uuid import uuid4
class Entry():
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)
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.')
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()