Files
loom/backend/app/models/channel_code.py
T
2026-04-24 17:46:03 +08:00

32 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""渠道码:内导(internal)/ 自然(natural)。与产品多对多。"""
from __future__ import annotations
from sqlalchemy import Column, ForeignKey, Integer, String, Table
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base, TimestampMixin
product_channel_code = Table(
"product_channel_code",
Base.metadata,
Column("product_id", Integer, ForeignKey("product.id", ondelete="CASCADE"), primary_key=True),
Column(
"channel_code_id",
Integer,
ForeignKey("channel_code.id", ondelete="CASCADE"),
primary_key=True,
),
)
class ChannelCode(Base, TimestampMixin):
__tablename__ = "channel_code"
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(64), nullable=False)
# INTERNAL / NATURAL
type: Mapped[str] = mapped_column(String(16), nullable=False, default="INTERNAL")
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
status: Mapped[str] = mapped_column(String(16), default="ACTIVE", nullable=False)