This commit is contained in:
22
orm/shout.py
22
orm/shout.py
@@ -4,11 +4,17 @@ from typing import Any
|
||||
from sqlalchemy import JSON, Boolean, ForeignKey, Index, Integer, PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
# Импорт Author отложен для избежания циклических импортов
|
||||
from auth.orm import Author
|
||||
from orm.base import BaseModel as Base
|
||||
from orm.reaction import Reaction
|
||||
from orm.topic import Topic
|
||||
|
||||
# Author уже импортирован в начале файла
|
||||
def get_author_model():
|
||||
"""Возвращает модель Author для использования в запросах"""
|
||||
return Author
|
||||
|
||||
|
||||
class ShoutTopic(Base):
|
||||
"""
|
||||
@@ -37,7 +43,7 @@ class ShoutTopic(Base):
|
||||
class ShoutReactionsFollower(Base):
|
||||
__tablename__ = "shout_reactions_followers"
|
||||
|
||||
follower: Mapped[int] = mapped_column(ForeignKey(Author.id), index=True)
|
||||
follower: Mapped[int] = mapped_column(ForeignKey("author.id"), index=True)
|
||||
shout: Mapped[int] = mapped_column(ForeignKey("shout.id"), index=True)
|
||||
auto: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
created_at: Mapped[int] = mapped_column(Integer, nullable=False, default=lambda: int(time.time()))
|
||||
@@ -64,7 +70,7 @@ class ShoutAuthor(Base):
|
||||
__tablename__ = "shout_author"
|
||||
|
||||
shout: Mapped[int] = mapped_column(ForeignKey("shout.id"), index=True)
|
||||
author: Mapped[int] = mapped_column(ForeignKey(Author.id), index=True)
|
||||
author: Mapped[int] = mapped_column(ForeignKey("author.id"), index=True)
|
||||
caption: Mapped[str | None] = mapped_column(String, nullable=True, default="")
|
||||
|
||||
# Определяем дополнительные индексы
|
||||
@@ -89,9 +95,9 @@ class Shout(Base):
|
||||
featured_at: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True)
|
||||
deleted_at: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True)
|
||||
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey(Author.id), nullable=False)
|
||||
updated_by: Mapped[int | None] = mapped_column(ForeignKey(Author.id), nullable=True)
|
||||
deleted_by: Mapped[int | None] = mapped_column(ForeignKey(Author.id), nullable=True)
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("author.id"), nullable=False)
|
||||
updated_by: Mapped[int | None] = mapped_column(ForeignKey("author.id"), nullable=True)
|
||||
deleted_by: Mapped[int | None] = mapped_column(ForeignKey("author.id"), nullable=True)
|
||||
community: Mapped[int] = mapped_column(ForeignKey("community.id"), nullable=False)
|
||||
|
||||
body: Mapped[str] = mapped_column(String, nullable=False, comment="Body")
|
||||
@@ -104,9 +110,9 @@ class Shout(Base):
|
||||
layout: Mapped[str] = mapped_column(String, nullable=False, default="article")
|
||||
media: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
|
||||
|
||||
authors = relationship(Author, secondary="shout_author")
|
||||
topics = relationship(Topic, secondary="shout_topic")
|
||||
reactions = relationship(Reaction)
|
||||
authors = relationship("Author", secondary="shout_author")
|
||||
topics = relationship("Topic", secondary="shout_topic")
|
||||
reactions = relationship("Reaction")
|
||||
|
||||
lang: Mapped[str] = mapped_column(String, nullable=False, default="ru", comment="Language")
|
||||
version_of: Mapped[int | None] = mapped_column(ForeignKey("shout.id"), nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user