fix shout
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from orm.rbac import Community, Operation, Resource, Permission, Role
|
||||
from orm.rbac import Operation, Resource, Permission, Role
|
||||
from orm.community import Community
|
||||
from orm.user import User
|
||||
from orm.message import Message
|
||||
from orm.topic import Topic
|
||||
from orm.notification import Notification
|
||||
from orm.shout import Shout
|
||||
from orm.shout import Shout, ShoutAuthor
|
||||
from orm.base import Base, engine
|
||||
|
||||
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification"]
|
||||
|
@@ -6,12 +6,10 @@ from orm.base import Base
|
||||
|
||||
class Community(Base):
|
||||
__tablename__ = 'community'
|
||||
# id is auto number
|
||||
# id is auto number
|
||||
name: str = Column(String, nullable=False, comment="Name")
|
||||
slug: str = Column(String, unique = True, nullable = False)
|
||||
desc: str = Column(String, nullable=False, default='')
|
||||
pic: str = Column(String, nullable=False, default='')
|
||||
# org_id: str = Column(ForeignKey("organization.id"), nullable=True)
|
||||
desc: str = Column(String, nullable=False, default='')
|
||||
pic: str = Column(String, nullable=False, default='')
|
||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||
createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Creator")
|
||||
|
13
orm/shout.py
13
orm/shout.py
@@ -5,11 +5,12 @@ from sqlalchemy.orm import relationship
|
||||
from orm import Permission, User, Topic
|
||||
from orm.base import Base
|
||||
|
||||
ShoutAuthors = Table('shout_authors',
|
||||
Base.metadata,
|
||||
Column('shout', Integer, ForeignKey('shout.id')),
|
||||
Column('user_id', Integer, ForeignKey('user.id'))
|
||||
)
|
||||
class ShoutAuthor(Base):
|
||||
__tablename__ = "shout_author"
|
||||
|
||||
id = None
|
||||
shout = Column(ForeignKey('shout.id'), primary_key = True)
|
||||
user = Column(ForeignKey('user.id'), primary_key = True)
|
||||
|
||||
ShoutTopics = Table('shout_topics',
|
||||
Base.metadata,
|
||||
@@ -45,7 +46,7 @@ class Shout(Base):
|
||||
title: str = Column(String, nullable = True)
|
||||
subtitle: str = Column(String, nullable = True)
|
||||
layout: str = Column(String, nullable = True)
|
||||
authors = relationship(lambda: User, secondary=ShoutAuthors) # NOTE: multiple authors
|
||||
authors = relationship(lambda: User, secondary=ShoutAuthor.__tablename__) # NOTE: multiple authors
|
||||
topics = relationship(lambda: Topic, secondary=ShoutTopics)
|
||||
rating: int = Column(Integer, nullable=True, comment="Rating")
|
||||
ratings = relationship(ShoutRatings, foreign_keys=ShoutRatings.shout_id)
|
||||
|
@@ -7,6 +7,7 @@ from sqlalchemy.orm import relationship
|
||||
from orm import Permission
|
||||
from orm.base import Base, local_session
|
||||
from orm.rbac import Role
|
||||
from orm.topic import Topic
|
||||
|
||||
class UserNotifications(Base):
|
||||
__tablename__ = 'user_notifications'
|
||||
@@ -26,14 +27,14 @@ class UserRatings(Base):
|
||||
|
||||
UserRoles = Table("user_roles",
|
||||
Base.metadata,
|
||||
Column('user_id', Integer, ForeignKey('user.id')),
|
||||
Column('role_id', Integer, ForeignKey('role.id'))
|
||||
Column('user_id', Integer, ForeignKey('user.id'), primary_key = True),
|
||||
Column('role_id', Integer, ForeignKey('role.id'), primary_key = True)
|
||||
)
|
||||
|
||||
UserTopics = Table("user_topics",
|
||||
Base.metadata,
|
||||
Column('user_id', Integer, ForeignKey('user.id')),
|
||||
Column('topic_id', Integer, ForeignKey('topic.id'))
|
||||
Column('user_id', Integer, ForeignKey('user.id'), primary_key = True),
|
||||
Column('topic_id', Integer, ForeignKey('topic.id'), primary_key = True)
|
||||
)
|
||||
|
||||
class User(Base):
|
||||
|
Reference in New Issue
Block a user