feat: типизация для tortoise ORM
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import enum
|
||||
from typing import TYPE_CHECKING
|
||||
from uuid import UUID
|
||||
|
||||
from tortoise import fields
|
||||
from tortoise.models import Model
|
||||
|
||||
from .base import TimestampedModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .external_channel import ExternalChannel
|
||||
from .user import User
|
||||
|
||||
|
||||
class TargetChannelStatus(str, enum.Enum):
|
||||
@@ -10,30 +17,25 @@ class TargetChannelStatus(str, enum.Enum):
|
||||
ARCHIVED = 'archived'
|
||||
|
||||
|
||||
class TargetChannel(Model):
|
||||
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)
|
||||
|
||||
user = fields.ForeignKeyField('models.User', related_name='target_channels', on_delete=fields.CASCADE, index=True)
|
||||
user: fields.ForeignKeyRelation['User'] = fields.ForeignKeyField(
|
||||
'models.User', related_name='target_channels', on_delete=fields.CASCADE, index=True
|
||||
)
|
||||
|
||||
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',
|
||||
)
|
||||
|
||||
# Reverse relations:
|
||||
# creatives: fields.ReverseRelation['Creative']
|
||||
# placements: fields.ReverseRelation['Placement']
|
||||
# subscriptions: fields.ReverseRelation['Subscription']
|
||||
if TYPE_CHECKING:
|
||||
user_id: UUID
|
||||
|
||||
class Meta:
|
||||
table = 'target_channel'
|
||||
|
||||
Reference in New Issue
Block a user