29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
"""
|
|
Food model for the application
|
|
"""
|
|
from datetime import datetime
|
|
from sqlalchemy import Column, String, Integer, DateTime, Float, Boolean, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class Food(Base):
|
|
"""Food model for storing food items and their nutritional information"""
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, index=True, nullable=False)
|
|
description = Column(String, nullable=True)
|
|
calories_per_100g = Column(Float, nullable=False)
|
|
protein_g = Column(Float, nullable=True)
|
|
carbs_g = Column(Float, nullable=True)
|
|
fat_g = Column(Float, nullable=True)
|
|
fiber_g = Column(Float, nullable=True)
|
|
is_verified = Column(Boolean, default=False)
|
|
# If created by user, store the user ID
|
|
created_by_id = Column(Integer, ForeignKey("user.id"), nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
created_by = relationship("User", backref="created_foods")
|
|
calorie_entries = relationship("CalorieEntry", back_populates="food") |