返回字段名更改
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, ConfigDict, field_serializer
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
@@ -20,13 +20,27 @@ class AccountUpdate(BaseModel):
|
||||
project_name: Optional[str] = None
|
||||
|
||||
class AccountResponse(AccountBase):
|
||||
account_id: int = Field(alias="id")
|
||||
account_id: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
populate_by_name = True
|
||||
model_config = ConfigDict(
|
||||
from_attributes=True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_orm_account(cls, account):
|
||||
"""从ORM对象创建响应对象"""
|
||||
return cls(
|
||||
account_id=account.id,
|
||||
username=account.username,
|
||||
password=account.password,
|
||||
status=account.status,
|
||||
today_updated=account.today_updated,
|
||||
project_name=account.project_name,
|
||||
created_at=account.created_at,
|
||||
updated_at=account.updated_at
|
||||
)
|
||||
|
||||
class AccountListRequest(BaseModel):
|
||||
skip: Optional[int] = 0
|
||||
|
||||
Reference in New Issue
Block a user