Files
django-vue3-admin-gd/ai_service/schemas/base.py
2025-07-18 22:14:37 +08:00

19 lines
679 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pydantic import BaseModel
from datetime import datetime
from typing import Optional
class ReadSchemaType(BaseModel):
"""
所有响应模型的基类包含公共字段和ORM转换配置
"""
id: int
created_at: Optional[datetime] = None # 数据创建时间(可选,部分模型可能没有)
updated_at: Optional[datetime] = None # 数据更新时间(可选)
class Config:
"""
配置Pydantic模型如何处理ORM对象
- from_attributes=True支持直接从SQLAlchemy ORM模型转换Pydantic v2
- 若使用Pydantic v1需替换为 orm_mode=True
"""
from_attributes = True