Improve the demo feature of the project
This commit is contained in:
@@ -128,12 +128,24 @@ class IngredientResponse(InventoryBaseSchema):
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
created_by: Optional[str]
|
||||
|
||||
|
||||
# Computed fields
|
||||
current_stock: Optional[float] = None
|
||||
is_low_stock: Optional[bool] = None
|
||||
needs_reorder: Optional[bool] = None
|
||||
|
||||
@validator('allergen_info', pre=True)
|
||||
def validate_allergen_info(cls, v):
|
||||
"""Convert empty lists or lists to empty dict, handle None"""
|
||||
if v is None:
|
||||
return None
|
||||
if isinstance(v, list):
|
||||
# If it's an empty list or a list, convert to empty dict
|
||||
return {} if len(v) == 0 else None
|
||||
if isinstance(v, dict):
|
||||
return v
|
||||
return None
|
||||
|
||||
|
||||
# ===== STOCK SCHEMAS =====
|
||||
|
||||
|
||||
Reference in New Issue
Block a user