from pydantic import BaseModel, Field from typing import Optional, List from datetime import datetime # 分类模式 class ClothingCategoryBase(BaseModel): """衣服分类基础模式""" name: str = Field(..., description="分类名称") class ClothingCategoryCreate(ClothingCategoryBase): """创建衣服分类请求""" pass class ClothingCategoryInDB(ClothingCategoryBase): """数据库中的衣服分类数据""" id: int create_time: datetime class Config: from_attributes = True class ClothingCategory(ClothingCategoryInDB): """衣服分类响应模式""" pass class ClothingCategoryUpdate(BaseModel): """更新衣服分类请求""" name: Optional[str] = Field(None, description="分类名称") # 衣服模式 class ClothingBase(BaseModel): """衣服基础模式""" clothing_category_id: int = Field(..., description="分类ID") image_url: str = Field(..., description="图片URL") class ClothingCreate(ClothingBase): """创建衣服请求""" pass class ClothingInDB(ClothingBase): """数据库中的衣服数据""" id: int create_time: datetime class Config: from_attributes = True class Clothing(ClothingInDB): """衣服响应模式""" pass class ClothingUpdate(BaseModel): """更新衣服请求""" clothing_category_id: Optional[int] = Field(None, description="分类ID") image_url: Optional[str] = Field(None, description="图片URL") # 带有分类信息的衣服响应 class ClothingWithCategory(Clothing): """包含分类信息的衣服响应""" category: ClothingCategory class Config: from_attributes = True