fix issue
This commit is contained in:
@@ -29,6 +29,16 @@ class TimestampMixin:
|
|||||||
DateTime, default=func.now(), onupdate=func.now(), comment="更新时间"
|
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):
|
class KnowledgePage(Base, TimestampMixin):
|
||||||
"""知识页面"""
|
"""知识页面"""
|
||||||
@@ -92,3 +102,13 @@ class WebsiteSettings(Base):
|
|||||||
updated_at: Mapped[datetime] = mapped_column(
|
updated_at: Mapped[datetime] = mapped_column(
|
||||||
DateTime, default=func.now(), onupdate=func.now(), comment="更新时间"
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user