修复:后端to_dict转换时间为本地时区,兼容新旧数据

This commit is contained in:
bwstudio
2026-04-18 22:34:15 +08:00
parent c08ca148e7
commit 9fb210970f
2 changed files with 7 additions and 1 deletions
Binary file not shown.
+7 -1
View File
@@ -70,6 +70,12 @@ def get_detection(detection_id):
# 为Detection模型添加to_dict方法
def detection_to_dict(self):
created_at = self.created_at
if created_at:
if created_at.tzinfo is None:
from datetime import timezone
created_at = created_at.replace(tzinfo=timezone.utc)
created_at = created_at.astimezone()
return {
'id': self.id,
'website_id': self.website_id,
@@ -77,7 +83,7 @@ def detection_to_dict(self):
'response_time': self.response_time,
'http_status': self.http_status,
'message': self.message,
'created_at': self.created_at.isoformat() if self.created_at else None
'created_at': created_at.isoformat() if created_at else None
}
Detection.to_dict = detection_to_dict