This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/resources/models.py
2018-08-09 21:46:54 +02:00

31 lines
859 B
Python

from datetime import datetime, timezone
from ereuse_devicehub.db import db
STR_SIZE = 64
STR_BIG_SIZE = 128
STR_SM_SIZE = 32
STR_XSM_SIZE = 16
class Thing(db.Model):
__abstract__ = True
# todo make updated to auto-update
updated = db.Column(db.TIMESTAMP(timezone=True),
nullable=False,
server_default=db.text('CURRENT_TIMESTAMP'))
updated.comment = """
When this was last changed.
"""
created = db.Column(db.TIMESTAMP(timezone=True),
nullable=False,
server_default=db.text('CURRENT_TIMESTAMP'))
created.comment = """
When Devicehub created this.
"""
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
if not self.created:
self.created = datetime.now(timezone.utc)