fix updateShout
This commit is contained in:
@@ -4,7 +4,7 @@ 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, ShoutAuthor
|
||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||
from orm.base import Base, engine
|
||||
|
||||
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification"]
|
||||
|
@@ -51,6 +51,12 @@ class Base(declarative_base()):
|
||||
session.commit()
|
||||
return self
|
||||
|
||||
def update(self, input):
|
||||
column_names = self.__table__.columns.keys()
|
||||
for (name, value) in input.items():
|
||||
if name in column_names:
|
||||
setattr(self, name, value)
|
||||
|
||||
def dict(self) -> Dict[str, Any]:
|
||||
column_names = self.__table__.columns.keys()
|
||||
return {c: getattr(self, c) for c in column_names}
|
||||
|
13
orm/shout.py
13
orm/shout.py
@@ -12,11 +12,12 @@ class ShoutAuthor(Base):
|
||||
shout = Column(ForeignKey('shout.id'), primary_key = True)
|
||||
user = Column(ForeignKey('user.id'), primary_key = True)
|
||||
|
||||
ShoutTopics = Table('shout_topics',
|
||||
Base.metadata,
|
||||
Column('shout', Integer, ForeignKey('shout.id')),
|
||||
Column('topic', Integer, ForeignKey('topic.id'))
|
||||
)
|
||||
class ShoutTopic(Base):
|
||||
__tablename__ = 'shout_topic'
|
||||
|
||||
id = None
|
||||
shout = Column(ForeignKey('shout.id'), primary_key = True)
|
||||
topic = Column(ForeignKey('topic.id'), primary_key = True)
|
||||
|
||||
class ShoutRatings(Base):
|
||||
__tablename__ = "user_ratings"
|
||||
@@ -47,7 +48,7 @@ class Shout(Base):
|
||||
subtitle: str = Column(String, nullable = True)
|
||||
layout: str = Column(String, nullable = True)
|
||||
authors = relationship(lambda: User, secondary=ShoutAuthor.__tablename__) # NOTE: multiple authors
|
||||
topics = relationship(lambda: Topic, secondary=ShoutTopics)
|
||||
topics = relationship(lambda: Topic, secondary=ShoutTopic.__tablename__)
|
||||
rating: int = Column(Integer, nullable=True, comment="Rating")
|
||||
ratings = relationship(ShoutRatings, foreign_keys=ShoutRatings.shout_id)
|
||||
old_id: str = Column(String, nullable = True)
|
||||
|
Reference in New Issue
Block a user