This commit is contained in:
@@ -26,6 +26,14 @@ class AuthorFollower(Base):
|
||||
auto = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
|
||||
class AuthorBookmark(Base):
|
||||
__tablename__ = "author_bookmark"
|
||||
|
||||
id = None # type: ignore
|
||||
author = Column(ForeignKey("author.id"), primary_key=True)
|
||||
shout = Column(ForeignKey("shout.id"), primary_key=True)
|
||||
|
||||
|
||||
class Author(Base):
|
||||
__tablename__ = "author"
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import time
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||
from requests import Session
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, func
|
||||
from sqlalchemy.ext.hybrid import hybrid_method
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from orm.author import Author
|
||||
@@ -27,3 +29,17 @@ class Community(Base):
|
||||
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
|
||||
|
||||
authors = relationship(Author, secondary="community_author")
|
||||
|
||||
@hybrid_method
|
||||
def get_stats(self, session: Session):
|
||||
from orm.shout import ShoutCommunity # Импорт здесь во избежание циклических зависимостей
|
||||
|
||||
shouts_count = (
|
||||
session.query(func.count(ShoutCommunity.shout_id)).filter(ShoutCommunity.community_id == self.id).scalar()
|
||||
)
|
||||
|
||||
followers_count = (
|
||||
session.query(func.count(CommunityFollower.author)).filter(CommunityFollower.community == self.id).scalar()
|
||||
)
|
||||
|
||||
return {"shouts": shouts_count, "followers": followers_count}
|
||||
|
@@ -5,8 +5,7 @@ from sqlalchemy import JSON, Column, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from orm.author import Author
|
||||
from services.db import Base, create_table_if_not_exists, engine
|
||||
from utils.logger import root_logger as logger
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class NotificationEntity(Enumeration):
|
||||
|
Reference in New Issue
Block a user