Spaces:
Sleeping
Sleeping
| from datetime import datetime, date | |
| from sqlalchemy import BigInteger, Column, DateTime, func | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.inspection import inspect | |
| Base = declarative_base() | |
| class BaseModel_(Base): | |
| __abstract__ = True # This model should not be instantiated directly | |
| __table_args__ = {"extend_existing": True} # Allow table extension | |
| created = Column(DateTime, server_default=func.now(), nullable=False) | |
| def to_dict(self, keys_not_to_include: list[str] = []) -> dict: | |
| return { | |
| c.key: ( | |
| getattr(self, c.key).isoformat() | |
| if isinstance(getattr(self, c.key), (datetime, date)) | |
| else getattr(self, c.key) | |
| ) | |
| for c in inspect(self).mapper.column_attrs | |
| if c.key not in keys_not_to_include | |
| } |