store views on the shouts table, remove the viewed table
This commit is contained in:
@@ -6,7 +6,6 @@ from orm.reaction import Reaction
|
||||
from orm.shout import Shout
|
||||
from orm.topic import Topic, TopicFollower
|
||||
from orm.user import User, UserRating
|
||||
from orm.viewed import ViewedEntry
|
||||
|
||||
# NOTE: keep orm module isolated
|
||||
|
||||
@@ -22,7 +21,6 @@ __all__ = [
|
||||
"Notification",
|
||||
"Reaction",
|
||||
"UserRating",
|
||||
"ViewedEntry"
|
||||
]
|
||||
|
||||
|
||||
@@ -35,5 +33,4 @@ def init_tables():
|
||||
Role.init_table()
|
||||
UserRating.init_table()
|
||||
Shout.init_table()
|
||||
ViewedEntry.init_table()
|
||||
print("[orm] tables initialized")
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String, JSON
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from base.orm import Base, local_session
|
||||
@@ -61,6 +61,7 @@ class Shout(Base):
|
||||
authors = relationship(lambda: User, secondary=ShoutAuthor.__tablename__)
|
||||
topics = relationship(lambda: Topic, secondary=ShoutTopic.__tablename__)
|
||||
|
||||
views = Column(Integer, default=0)
|
||||
reactions = relationship(lambda: Reaction)
|
||||
|
||||
# TODO: these field should be used or modified
|
||||
|
@@ -1,24 +0,0 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer
|
||||
from base.orm import Base, local_session
|
||||
|
||||
|
||||
class ViewedEntry(Base):
|
||||
__tablename__ = "viewed"
|
||||
|
||||
viewer = Column(ForeignKey("user.id"), index=True, default=1)
|
||||
shout = Column(ForeignKey("shout.id"), index=True, default=1)
|
||||
amount = Column(Integer, default=1)
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
entry = {
|
||||
"amount": 0
|
||||
}
|
||||
viewed = ViewedEntry.create(**entry)
|
||||
session.add(viewed)
|
||||
session.commit()
|
Reference in New Issue
Block a user