Files
tgex-backend/src/domain/target_channel.py
Artem Tsyrulnikov af32e2a507 feat: add workspace
2025-12-13 22:09:55 +03:00

44 lines
1.3 KiB
Python

import enum
from typing import TYPE_CHECKING
from uuid import UUID
from tortoise import fields
from .base import TimestampedModel
if TYPE_CHECKING:
from .external_channel import ExternalChannel
from .workspace import Workspace
class TargetChannelStatus(str, enum.Enum):
ACTIVE = 'active'
INACTIVE = 'inactive'
ARCHIVED = 'archived'
class TargetChannel(TimestampedModel):
id = fields.UUIDField(pk=True)
telegram_id = fields.BigIntField(unique=True, index=True)
title = fields.CharField(max_length=255)
username = fields.CharField(max_length=255, null=True, index=True)
status = fields.CharEnumField(TargetChannelStatus, default=TargetChannelStatus.ACTIVE)
workspace: fields.ForeignKeyRelation['Workspace'] = fields.ForeignKeyField(
'models.Workspace', related_name='target_channels', on_delete=fields.CASCADE, index=True
)
external_channels: fields.ManyToManyRelation['ExternalChannel'] = fields.ManyToManyField(
'models.ExternalChannel',
related_name='target_channels',
through='target_external_channel',
forward_key='external_channel_id',
backward_key='target_channel_id',
)
if TYPE_CHECKING:
workspace_id: UUID
class Meta:
table = 'target_channel'