feat: optimize parse_string_datetimes
This commit is contained in:
@@ -35,7 +35,9 @@ class BasicModel(SQLModel):
|
||||
|
||||
# 定义模型验证器,在数据解析前(mode='before')执行,用于处理字符串格式的日期时间
|
||||
@model_validator(mode='before')
|
||||
def parse_string_datetimes(cls, data: dict) -> dict:
|
||||
def parse_string_datetimes(cls, data: dict | None) -> dict:
|
||||
if not data:
|
||||
return
|
||||
# 处理datetime类型字段:将字符串格式的日期时间转换为datetime对象
|
||||
datetime_fields = {
|
||||
k: datetime.strptime(v, "%Y-%m-%d %H:%M:%S") # 使用strptime解析字符串为datetime
|
||||
|
||||
Reference in New Issue
Block a user