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