fooder-api/fooder/domain/entry.py

24 lines
755 B
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from sqlalchemy import ForeignKey, Integer
from sqlalchemy.orm import Mapped, mapped_column, relationship
from fooder.domain.base import Base, CommonMixin, EntryMacrosMixin
from fooder.domain.product import Product
if TYPE_CHECKING:
from fooder.domain.meal import Meal
class Entry(Base, CommonMixin, EntryMacrosMixin):
"""Entry."""
grams: Mapped[float]
product_id: Mapped[int] = mapped_column(
Integer, ForeignKey("product.id"), index=True
)
product: Mapped[Product] = relationship(lazy="selectin")
meal_id: Mapped[int] = mapped_column(Integer, ForeignKey("meal.id"), index=True)
meal: Mapped[Meal] = relationship(back_populates="entries")