feat: переезд на tortose
This commit is contained in:
@@ -1,36 +1,39 @@
|
||||
import uuid
|
||||
from enum import StrEnum
|
||||
from typing import TYPE_CHECKING
|
||||
import enum
|
||||
|
||||
from sqlalchemy import BigInteger, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from src import domain
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import ExternalChannel
|
||||
from .creative import Creative
|
||||
from .user import User
|
||||
from tortoise import fields
|
||||
from tortoise.models import Model
|
||||
|
||||
|
||||
class TargetChannelStatus(StrEnum):
|
||||
class TargetChannelStatus(str, enum.Enum):
|
||||
ACTIVE = 'active'
|
||||
INACTIVE = 'inactive'
|
||||
ARCHIVED = 'archived'
|
||||
|
||||
|
||||
class TargetChannel(domain.Base):
|
||||
telegram_id: Mapped[int] = mapped_column(BigInteger, unique=True, index=True)
|
||||
title: Mapped[str]
|
||||
username: Mapped[str | None] = mapped_column(index=True)
|
||||
status: Mapped[TargetChannelStatus] = mapped_column(default=TargetChannelStatus.ACTIVE)
|
||||
class TargetChannel(Model):
|
||||
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)
|
||||
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('user.id'), index=True)
|
||||
user: Mapped['User'] = relationship(back_populates='target_channels')
|
||||
user = fields.ForeignKeyField('models.User', related_name='target_channels', on_delete=fields.CASCADE, index=True)
|
||||
|
||||
external_channels: Mapped[list['ExternalChannel']] = relationship(
|
||||
secondary='target_external_channel',
|
||||
back_populates='target_channels',
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
updated_at = fields.DatetimeField(auto_now=True)
|
||||
deleted_at = fields.DatetimeField(null=True)
|
||||
|
||||
# Many-to-many с ExternalChannel через таблицу target_external_channel
|
||||
external_channels: fields.ManyToManyRelation['ExternalChannel'] = fields.ManyToManyField(
|
||||
'models.ExternalChannel',
|
||||
related_name='target_channels',
|
||||
through='target_external_channel',
|
||||
)
|
||||
|
||||
creatives: Mapped[list['Creative']] = relationship(back_populates='target_channel')
|
||||
# Reverse relations:
|
||||
# creatives: fields.ReverseRelation['Creative']
|
||||
# placements: fields.ReverseRelation['Placement']
|
||||
# subscriptions: fields.ReverseRelation['Subscription']
|
||||
|
||||
class Meta:
|
||||
table = 'target_channel'
|
||||
|
||||
Reference in New Issue
Block a user