from sqlalchemy import ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from models.base import BaseModel from models.mixins import IdMixin, SoftDeleteMixin class Product(BaseModel, IdMixin, SoftDeleteMixin): __tablename__ = "fulfillment_base_products" name: Mapped[str] = mapped_column() article: Mapped[str] = mapped_column(index=True) factory_article: Mapped[str] = mapped_column( index=True, default="", server_default="" ) brand: Mapped[str] = mapped_column(default="", comment="Бренд") color: Mapped[str] = mapped_column(default="", comment="Цвет") composition: Mapped[str] = mapped_column(default="", comment="Состав") size: Mapped[str] = mapped_column(default="", comment="Размер") additional_info: Mapped[str] = mapped_column( default="", comment="Дополнительная информация" ) images: Mapped[list["ProductImage"]] = relationship( "ProductImage", back_populates="product", lazy="selectin", cascade="all, delete-orphan", ) class ProductImage(BaseModel, IdMixin): __tablename__ = "fulfillment_base_product_images" product_id: Mapped[int] = mapped_column(ForeignKey("fulfillment_base_products.id")) product: Mapped["Product"] = relationship(back_populates="images") image_url: Mapped[str] = mapped_column(nullable=False)