feat: типизация для tortoise ORM

This commit is contained in:
Artem Tsyrulnikov
2025-12-11 12:01:20 +03:00
parent 0f0de396e1
commit 02729ce81b
17 changed files with 181 additions and 263 deletions

View File

@@ -1,8 +1,16 @@
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 .target_channel import TargetChannel
from .user import User
class ExternalChannel(Model):
class ExternalChannel(TimestampedModel):
id = fields.UUIDField(pk=True)
telegram_id = fields.BigIntField(unique=True, index=True)
title = fields.CharField(max_length=255)
@@ -10,17 +18,14 @@ class ExternalChannel(Model):
description = fields.TextField(null=True)
subscribers_count = fields.IntField(null=True)
user = fields.ForeignKeyField('models.User', related_name='external_channels', on_delete=fields.CASCADE, index=True)
user: fields.ForeignKeyRelation['User'] = fields.ForeignKeyField(
'models.User', related_name='external_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)
target_channels: fields.ManyToManyRelation['TargetChannel']
# Many-to-many с TargetChannel (определено в TargetChannel)
# target_channels: fields.ManyToManyRelation['TargetChannel']
# Reverse relations:
# placements: fields.ReverseRelation['Placement']
if TYPE_CHECKING:
user_id: UUID
class Meta:
table = 'external_channel'