commynity-cudl
All checks were successful
Deploy on push / deploy (push) Successful in 1m5s

This commit is contained in:
2024-10-21 16:42:30 +03:00
parent c6f160c8cf
commit a4e48eb3f4
6 changed files with 106 additions and 4 deletions

View File

@@ -1,11 +1,12 @@
import enum
import time
from sqlalchemy import ARRAY, Column, ForeignKey, Integer, String, func
from sqlalchemy import ARRAY, Column, ForeignKey, Integer, String, distinct, func
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship
from orm.author import Author
from orm.shout import Shout
from services.db import Base
@@ -45,8 +46,7 @@ class Community(Base):
desc = Column(String, nullable=False, default="")
pic = Column(String, nullable=False, default="")
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
authors = relationship(Author, secondary="community_author")
created_by = Column(ForeignKey("author.id"), nullable=False)
@hybrid_property
def stat(self):
@@ -74,3 +74,15 @@ class CommunityStats:
.filter(CommunityFollower.community == self.community.id)
.scalar()
)
@property
def authors(self):
# author has a shout with community id and featured_at is not null
return (
self.community.session.query(func.count(distinct(Author.id)))
.join(Shout)
.filter(
Shout.community_id == self.community.id, Shout.featured_at.is_not(None), Author.id.in_(Shout.authors)
)
.scalar()
)