32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
"""产品(平台下的业务实体)。"""
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base, TimestampMixin
|
|
from app.models.channel_code import ChannelCode, product_channel_code
|
|
|
|
|
|
class Product(Base, TimestampMixin):
|
|
__tablename__ = "product"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), nullable=False, unique=True)
|
|
name: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
platform_id: Mapped[int | None] = mapped_column(
|
|
ForeignKey("platform.id", ondelete="SET NULL"), nullable=True, index=True
|
|
)
|
|
dept_id: Mapped[int | None] = mapped_column(
|
|
ForeignKey("organization.id", ondelete="SET NULL"), nullable=True, index=True
|
|
)
|
|
owner_id: Mapped[int | None] = mapped_column(
|
|
ForeignKey("user.id", ondelete="SET NULL"), nullable=True, index=True
|
|
)
|
|
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
status: Mapped[str] = mapped_column(String(16), default="ACTIVE", nullable=False)
|
|
|
|
channel_codes: Mapped[list[ChannelCode]] = relationship(
|
|
"ChannelCode", secondary=product_channel_code, lazy="selectin"
|
|
)
|