feat: переезд на tortose
This commit is contained in:
@@ -1,27 +1,32 @@
|
||||
import uuid
|
||||
from enum import StrEnum
|
||||
from typing import TYPE_CHECKING
|
||||
import enum
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from src import domain
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .target_channel import TargetChannel
|
||||
from tortoise import fields
|
||||
from tortoise.models import Model
|
||||
|
||||
|
||||
class CreativeStatus(StrEnum):
|
||||
class CreativeStatus(str, enum.Enum):
|
||||
ACTIVE = 'active'
|
||||
ARCHIVED = 'archived'
|
||||
|
||||
|
||||
class Creative(domain.Base):
|
||||
name: Mapped[str]
|
||||
text: Mapped[str]
|
||||
status: Mapped[CreativeStatus]
|
||||
placements_count: Mapped[int] = mapped_column(default=0, server_default='0')
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('user.id'), index=True)
|
||||
class Creative(Model):
|
||||
id = fields.UUIDField(pk=True)
|
||||
name = fields.CharField(max_length=255)
|
||||
text = fields.TextField()
|
||||
status = fields.CharEnumField(CreativeStatus, default=CreativeStatus.ACTIVE)
|
||||
placements_count = fields.IntField(default=0)
|
||||
|
||||
target_channel_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('target_channel.id'), index=True)
|
||||
target_channel: Mapped['TargetChannel'] = relationship(back_populates='creatives')
|
||||
user = fields.ForeignKeyField('models.User', related_name='creatives', on_delete=fields.CASCADE, index=True)
|
||||
target_channel = fields.ForeignKeyField(
|
||||
'models.TargetChannel', related_name='creatives', 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)
|
||||
|
||||
# Reverse relations:
|
||||
# placements: fields.ReverseRelation['Placement']
|
||||
|
||||
class Meta:
|
||||
table = 'creative'
|
||||
|
||||
Reference in New Issue
Block a user