some orm fixes
This commit is contained in:
parent
47b285f8ac
commit
56a1467d3c
|
@ -1,8 +1,9 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, String, ForeignKey, DateTime
|
from sqlalchemy import Boolean, Column, String, ForeignKey, DateTime
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
from base.orm import Base
|
from base.orm import Base
|
||||||
|
from orm.user import User
|
||||||
|
|
||||||
|
|
||||||
class CollabAuthor(Base):
|
class CollabAuthor(Base):
|
||||||
|
@ -21,5 +22,6 @@ class Collab(Base):
|
||||||
title = Column(String, nullable=True, comment="Title")
|
title = Column(String, nullable=True, comment="Title")
|
||||||
body = Column(String, nullable=True, comment="Body")
|
body = Column(String, nullable=True, comment="Body")
|
||||||
pic = Column(String, nullable=True, comment="Picture")
|
pic = Column(String, nullable=True, comment="Picture")
|
||||||
|
authors = relationship(lambda: User, secondary=CollabAuthor.__tablename__)
|
||||||
createdAt = Column(DateTime, default=datetime.now, comment="Created At")
|
createdAt = Column(DateTime, default=datetime.now, comment="Created At")
|
||||||
createdBy = Column(ForeignKey("user.id"), comment="Created By")
|
createdBy = Column(ForeignKey("user.id"), comment="Created By")
|
||||||
|
|
20
orm/shout.py
20
orm/shout.py
|
@ -67,12 +67,14 @@ class Shout(Base):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init_table():
|
def init_table():
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
entry = {
|
s = session.query(Shout).first()
|
||||||
"slug": "genesis-block",
|
if not s:
|
||||||
"body": "",
|
entry = {
|
||||||
"title": "Ничего",
|
"slug": "genesis-block",
|
||||||
"lang": "ru"
|
"body": "",
|
||||||
}
|
"title": "Ничего",
|
||||||
s = Shout.create(**entry)
|
"lang": "ru"
|
||||||
session.add(s)
|
}
|
||||||
session.commit()
|
s = Shout.create(**entry)
|
||||||
|
session.add(s)
|
||||||
|
session.commit()
|
||||||
|
|
|
@ -7,7 +7,7 @@ class ViewedEntry(Base):
|
||||||
__tablename__ = "viewed"
|
__tablename__ = "viewed"
|
||||||
|
|
||||||
viewer = Column(ForeignKey("user.slug"), default='anonymous')
|
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)
|
amount = Column(Integer, default=1)
|
||||||
createdAt = Column(
|
createdAt = Column(
|
||||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||||
|
@ -17,7 +17,6 @@ class ViewedEntry(Base):
|
||||||
def init_table():
|
def init_table():
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
entry = {
|
entry = {
|
||||||
"shout": "genesis-block",
|
|
||||||
"amount": 0
|
"amount": 0
|
||||||
}
|
}
|
||||||
viewed = ViewedEntry.create(**entry)
|
viewed = ViewedEntry.create(**entry)
|
||||||
|
|
|
@ -12,7 +12,8 @@ class TopicStorage:
|
||||||
topics = session.query(Topic)
|
topics = session.query(Topic)
|
||||||
self.topics = dict([(topic.slug, topic) for topic in topics])
|
self.topics = dict([(topic.slug, topic) for topic in topics])
|
||||||
for tpc in self.topics.values():
|
for tpc in self.topics.values():
|
||||||
self.load_parents(tpc)
|
# self.load_parents(tpc)
|
||||||
|
pass
|
||||||
|
|
||||||
print("[zine.topics] %d precached" % len(self.topics.keys()))
|
print("[zine.topics] %d precached" % len(self.topics.keys()))
|
||||||
|
|
||||||
|
@ -64,4 +65,4 @@ class TopicStorage:
|
||||||
self = TopicStorage
|
self = TopicStorage
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
self.topics[topic.slug] = topic
|
self.topics[topic.slug] = topic
|
||||||
self.load_parents(topic)
|
# self.load_parents(topic)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user