修复:后端to_dict转换时间为本地时区,兼容新旧数据
This commit is contained in:
Binary file not shown.
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user