Update to support Pydantic v2 syntax
- 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
This commit is contained in:
parent
b9ff2c5c99
commit
26ee3102eb
@ -16,5 +16,6 @@ class Activity(ActivityBase):
|
||||
id: int
|
||||
user_id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
model_config = {
|
||||
"from_attributes": True
|
||||
}
|
@ -2,6 +2,9 @@ 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):
|
||||
@ -29,8 +32,9 @@ class ClientInDBBase(ClientBase):
|
||||
id: int
|
||||
user_id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
model_config = {
|
||||
"from_attributes": True
|
||||
}
|
||||
|
||||
|
||||
# Properties to return via API
|
||||
@ -45,5 +49,4 @@ class ClientInDB(ClientInDBBase):
|
||||
|
||||
# Client with invoices
|
||||
class ClientWithInvoices(Client):
|
||||
from app.schemas.invoice import Invoice
|
||||
invoices: List[Invoice] = []
|
@ -1,7 +1,7 @@
|
||||
from datetime import date
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
||||
# Invoice Item schemas
|
||||
@ -25,8 +25,9 @@ class InvoiceItemInDBBase(InvoiceItemBase):
|
||||
id: int
|
||||
invoice_id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
model_config = {
|
||||
"from_attributes": True
|
||||
}
|
||||
|
||||
|
||||
class InvoiceItem(InvoiceItemInDBBase):
|
||||
@ -42,7 +43,7 @@ class InvoiceBase(BaseModel):
|
||||
due_date: Optional[date] = None
|
||||
notes: Optional[str] = None
|
||||
|
||||
@validator("status")
|
||||
@field_validator("status")
|
||||
def status_validator(cls, v):
|
||||
allowed_statuses = ["draft", "sent", "paid"]
|
||||
if v not in allowed_statuses:
|
||||
@ -67,8 +68,9 @@ class InvoiceInDBBase(InvoiceBase):
|
||||
total_amount: float
|
||||
pdf_path: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
model_config = {
|
||||
"from_attributes": True
|
||||
}
|
||||
|
||||
|
||||
class Invoice(InvoiceInDBBase):
|
||||
|
@ -1,6 +1,9 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field, validator
|
||||
from pydantic import BaseModel, EmailStr, Field, field_validator
|
||||
|
||||
# Import at module level to avoid circular imports
|
||||
from app.schemas.client import Client
|
||||
|
||||
|
||||
# Shared properties
|
||||
@ -17,7 +20,7 @@ class UserBase(BaseModel):
|
||||
class UserCreate(UserBase):
|
||||
password: str = Field(..., min_length=8)
|
||||
|
||||
@validator("password")
|
||||
@field_validator("password")
|
||||
def password_validation(cls, v):
|
||||
if len(v) < 8:
|
||||
raise ValueError("Password must be at least 8 characters long")
|
||||
@ -30,7 +33,7 @@ class UserUpdate(UserBase):
|
||||
full_name: Optional[str] = None
|
||||
password: Optional[str] = None
|
||||
|
||||
@validator("password")
|
||||
@field_validator("password")
|
||||
def password_validation(cls, v):
|
||||
if v is not None and len(v) < 8:
|
||||
raise ValueError("Password must be at least 8 characters long")
|
||||
@ -41,8 +44,9 @@ class UserUpdate(UserBase):
|
||||
class UserInDBBase(UserBase):
|
||||
id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
model_config = {
|
||||
"from_attributes": True
|
||||
}
|
||||
|
||||
|
||||
# Properties to return via API
|
||||
@ -57,5 +61,4 @@ class UserInDB(UserInDBBase):
|
||||
|
||||
# User with clients
|
||||
class UserWithClients(User):
|
||||
from app.schemas.client import Client
|
||||
clients: List[Client] = []
|
Loading…
x
Reference in New Issue
Block a user