some orm fixes

This commit is contained in:
tonyrewin 2022-11-19 15:02:45 +03:00
parent 47b285f8ac
commit 56a1467d3c
4 changed files with 18 additions and 14 deletions

View File

@ -1,8 +1,9 @@
from datetime import datetime
from sqlalchemy import Boolean, Column, String, ForeignKey, DateTime
from sqlalchemy.orm import relationship
from base.orm import Base
from orm.user import User
class CollabAuthor(Base):
@ -21,5 +22,6 @@ class Collab(Base):
title = Column(String, nullable=True, comment="Title")
body = Column(String, nullable=True, comment="Body")
pic = Column(String, nullable=True, comment="Picture")
authors = relationship(lambda: User, secondary=CollabAuthor.__tablename__)
createdAt = Column(DateTime, default=datetime.now, comment="Created At")
createdBy = Column(ForeignKey("user.id"), comment="Created By")

View File

@ -67,12 +67,14 @@ class Shout(Base):
@staticmethod
def init_table():
with local_session() as session:
entry = {
"slug": "genesis-block",
"body": "",
"title": "Ничего",
"lang": "ru"
}
s = Shout.create(**entry)
session.add(s)
session.commit()
s = session.query(Shout).first()
if not s:
entry = {
"slug": "genesis-block",
"body": "",
"title": "Ничего",
"lang": "ru"
}
s = Shout.create(**entry)
session.add(s)
session.commit()

View File

@ -7,7 +7,7 @@ class ViewedEntry(Base):
__tablename__ = "viewed"
viewer = Column(ForeignKey("user.slug"), default='anonymous')
shout = Column(ForeignKey("shout.slug"))
shout = Column(ForeignKey("shout.slug"), default="genesis-block")
amount = Column(Integer, default=1)
createdAt = Column(
DateTime, nullable=False, default=datetime.now, comment="Created at"
@ -17,7 +17,6 @@ class ViewedEntry(Base):
def init_table():
with local_session() as session:
entry = {
"shout": "genesis-block",
"amount": 0
}
viewed = ViewedEntry.create(**entry)

View File

@ -12,7 +12,8 @@ class TopicStorage:
topics = session.query(Topic)
self.topics = dict([(topic.slug, topic) for topic in topics])
for tpc in self.topics.values():
self.load_parents(tpc)
# self.load_parents(tpc)
pass
print("[zine.topics] %d precached" % len(self.topics.keys()))
@ -64,4 +65,4 @@ class TopicStorage:
self = TopicStorage
async with self.lock:
self.topics[topic.slug] = topic
self.load_parents(topic)
# self.load_parents(topic)