feat: creatives and external channels
This commit is contained in:
33
src/domain/external_channel.py
Normal file
33
src/domain/external_channel.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import uuid
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import BigInteger, Column, ForeignKey, Table
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from src import domain
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import TargetChannel
|
||||
|
||||
# M2M association table between TargetChannel and ExternalChannel
|
||||
target_channel_external_channel = Table(
|
||||
'target_channel_external_channels',
|
||||
domain.Base.metadata,
|
||||
Column('target_channel_id', ForeignKey('targetchannels.id', ondelete='CASCADE'), primary_key=True),
|
||||
Column('external_channel_id', ForeignKey('externalchannels.id', ondelete='CASCADE'), primary_key=True),
|
||||
)
|
||||
|
||||
|
||||
class ExternalChannel(domain.Base):
|
||||
telegram_id: Mapped[int] = mapped_column(BigInteger, unique=True, index=True)
|
||||
title: Mapped[str]
|
||||
username: Mapped[str | None] = mapped_column(index=True)
|
||||
description: Mapped[str | None]
|
||||
subscribers_count: Mapped[int | None]
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('users.id'), index=True)
|
||||
|
||||
# M2M relationship with target channels
|
||||
target_channels: Mapped[list['TargetChannel']] = relationship(
|
||||
secondary=target_channel_external_channel,
|
||||
back_populates='external_channels',
|
||||
)
|
||||
Reference in New Issue
Block a user