fix(phase1): add photo fields to schemas and set datetime default
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, field_serializer
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# --- Categories ---
|
||||
@@ -54,6 +55,9 @@ class ItemBase(BaseModel):
|
||||
image_url: Optional[str] = None
|
||||
box_label: Optional[str] = None
|
||||
labels_data: Optional[str] = None
|
||||
photo_path: Optional[str] = None
|
||||
photo_thumbnail_path: Optional[str] = None
|
||||
photo_upload_date: Optional[datetime] = None
|
||||
|
||||
|
||||
class ItemCreate(ItemBase):
|
||||
@@ -65,3 +69,8 @@ class Item(ItemBase):
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@field_serializer('photo_upload_date', when_used='json')
|
||||
def serialize_photo_upload_date(self, value: Optional[datetime]) -> Optional[str]:
|
||||
"""Serialize datetime to ISO format string for JSON."""
|
||||
return value.isoformat() if value else None
|
||||
|
||||
Reference in New Issue
Block a user