38 lines
1.9 KiB
Python
38 lines
1.9 KiB
Python
"""食谱模型 - 支持热量识别与营养分析"""
|
|
from .base import Base
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from sqlalchemy import BigInteger, Integer, VARCHAR, Text, Float, JSON
|
|
from typing import Optional
|
|
|
|
|
|
class Recipe(Base):
|
|
__tablename__ = "recipes"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(VARCHAR(200), nullable=False)
|
|
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
image_url: Mapped[Optional[str]] = mapped_column(VARCHAR(500), nullable=True)
|
|
# 营养信息
|
|
calories: Mapped[Optional[float]] = mapped_column(Float, nullable=True, comment="热量(千卡)")
|
|
protein: Mapped[Optional[float]] = mapped_column(Float, nullable=True, comment="蛋白质(克)")
|
|
fat: Mapped[Optional[float]] = mapped_column(Float, nullable=True, comment="脂肪(克)")
|
|
carbs: Mapped[Optional[float]] = mapped_column(Float, nullable=True, comment="碳水化合物(克)")
|
|
fiber: Mapped[Optional[float]] = mapped_column(Float, nullable=True, comment="膳食纤维(克)")
|
|
# AI 识别相关
|
|
ai_recognition_confidence: Mapped[Optional[float]] = mapped_column(
|
|
Float, nullable=True, comment="AI 识别置信度 0-1"
|
|
)
|
|
ai_analysis_result: Mapped[Optional[dict]] = mapped_column(
|
|
JSON, nullable=True, comment="AI 识别完整结果"
|
|
)
|
|
# 分类
|
|
category: Mapped[Optional[str]] = mapped_column(VARCHAR(50), nullable=True, comment="菜品分类")
|
|
cuisine: Mapped[Optional[str]] = mapped_column(VARCHAR(50), nullable=True, comment="菜系")
|
|
# 状态
|
|
status: Mapped[str] = mapped_column(
|
|
VARCHAR(20), nullable=False, default="draft", comment="draft/published/archived"
|
|
)
|
|
# 用户标注
|
|
user_notes: Mapped[Optional[str]] = mapped_column(Text, nullable=True, comment="用户备注")
|
|
is_favorite: Mapped[bool] = mapped_column(default=False, comment="是否收藏")
|