
- Fixed circular imports in schema files by moving imports to module level - Changed orm_mode=True to model_config with from_attributes=True - Updated validator decorators to field_validator in all schema files - Properly annotated fields in all schema files for Pydantic v2 compatibility
52 lines
1.0 KiB
Python
52 lines
1.0 KiB
Python
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel, EmailStr
|
|
|
|
# Import at the top level to avoid circular imports
|
|
from app.schemas.invoice import Invoice
|
|
|
|
|
|
# Shared properties
|
|
class ClientBase(BaseModel):
|
|
name: str
|
|
email: EmailStr
|
|
company_name: Optional[str] = None
|
|
address: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
notes: Optional[str] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class ClientCreate(ClientBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class ClientUpdate(ClientBase):
|
|
name: Optional[str] = None
|
|
email: Optional[EmailStr] = None
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class ClientInDBBase(ClientBase):
|
|
id: int
|
|
user_id: int
|
|
|
|
model_config = {
|
|
"from_attributes": True
|
|
}
|
|
|
|
|
|
# Properties to return via API
|
|
class Client(ClientInDBBase):
|
|
pass
|
|
|
|
|
|
# Properties stored in DB
|
|
class ClientInDB(ClientInDBBase):
|
|
pass
|
|
|
|
|
|
# Client with invoices
|
|
class ClientWithInvoices(Client):
|
|
invoices: List[Invoice] = [] |