From 397a8d864130038117c92a52f6f48631047b1443 Mon Sep 17 00:00:00 2001 From: EduBrain Dev Date: Tue, 14 Apr 2026 21:10:05 +0800 Subject: [PATCH] fix issue --- app/models/base.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/models/base.py b/app/models/base.py index 1c08a58..1c47e87 100644 --- a/app/models/base.py +++ b/app/models/base.py @@ -29,6 +29,16 @@ class TimestampMixin: DateTime, default=func.now(), onupdate=func.now(), comment="更新时间" ) + def to_dict(self) -> Dict[str, Any]: + """将模型转为字典""" + result = {} + for col in self.__table__.columns: + val = getattr(self, col.name) + if isinstance(val, datetime): + val = val.isoformat() + result[col.name] = val + return result + class KnowledgePage(Base, TimestampMixin): """知识页面""" @@ -92,3 +102,13 @@ class WebsiteSettings(Base): updated_at: Mapped[datetime] = mapped_column( DateTime, default=func.now(), onupdate=func.now(), comment="更新时间" ) + + def to_dict(self) -> Dict[str, Any]: + """将模型转为字典""" + result = {} + for col in self.__table__.columns: + val = getattr(self, col.name) + if isinstance(val, datetime): + val = val.isoformat() + result[col.name] = val + return result