update topics logix

This commit is contained in:
2021-10-28 13:42:34 +03:00
parent 0d87f52d3a
commit 741ede054d
9 changed files with 79 additions and 13 deletions

View File

@@ -2,14 +2,14 @@ from orm.rbac import Operation, Resource, Permission, Role
from orm.community import Community
from orm.user import User, UserRating
from orm.message import Message
from orm.topic import Topic
from orm.topic import Topic, TopicSubscription
from orm.notification import Notification
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay,\
ShoutRatingStorage, ShoutViewStorage
from orm.base import Base, engine, local_session
from orm.comment import Comment, CommentRating
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification", "ShoutRating", "Comment", "CommentRating", "UserRating"]
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "TopicSubscription", "Notification", "ShoutRating", "Comment", "CommentRating", "UserRating"]
Base.metadata.create_all(engine)
Operation.init_table()

View File

@@ -11,13 +11,18 @@ Connection = Table('topic_connections',
UniqueConstraint('parent', 'child', name='unique_usage')
)
class TopicSubscription(Base):
__tablename__ = "topic_subscrptions"
id = None
topic = Column(ForeignKey('topic.slug'), primary_key = True)
user = Column(ForeignKey('user.id'), primary_key = True)
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
class Topic(Base):
__tablename__ = 'topic'
slug: str = Column(String, unique = True, nullable = False)
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
title: str = Column(String, nullable=False, comment="Title")
body: str = Column(String, nullable=True, comment="Body")
pic: str = Column(String, nullable=True, comment="Picture")
@@ -26,4 +31,5 @@ class Topic(Base):
parents = relationship(lambda: Topic, secondary=Connection, primaryjoin=slug==Connection.c.parent, secondaryjoin=slug==Connection.c.child, viewonly=True)
# list of Topics where the current node is the "parent"
children = relationship(lambda: Topic, secondary=Connection, primaryjoin=slug==Connection.c.child, secondaryjoin=slug==Connection.c.parent)
community = Column(ForeignKey("community.slug"), nullable=True, comment="Community")