2021-06-28 09:08:09 +00:00
|
|
|
from typing import List
|
|
|
|
from datetime import datetime
|
2021-08-20 08:08:32 +00:00
|
|
|
from sqlalchemy import Table, Column, Integer, String, ForeignKey, DateTime, Boolean
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from orm import Permission, User, Topic
|
2021-06-28 09:08:09 +00:00
|
|
|
from orm.base import Base
|
|
|
|
|
2021-08-20 08:08:32 +00:00
|
|
|
ShoutAuthors = Table('shout_authors',
|
|
|
|
Base.metadata,
|
|
|
|
Column('shout', String, ForeignKey('shout.slug')),
|
|
|
|
Column('user_id', Integer, ForeignKey('user.id'))
|
|
|
|
)
|
|
|
|
|
|
|
|
ShoutTopics = Table('shout_topics',
|
|
|
|
Base.metadata,
|
|
|
|
Column('shout', String, ForeignKey('shout.slug')),
|
|
|
|
Column('topic', String, ForeignKey('topic.slug'))
|
|
|
|
)
|
2021-06-28 09:08:09 +00:00
|
|
|
|
|
|
|
class Shout(Base):
|
2021-08-07 16:14:20 +00:00
|
|
|
__tablename__ = 'shout'
|
2021-06-28 09:08:09 +00:00
|
|
|
|
2021-08-23 14:46:05 +00:00
|
|
|
id = None
|
2021-08-08 12:23:12 +00:00
|
|
|
slug: str = Column(String, primary_key=True)
|
2021-08-19 15:33:39 +00:00
|
|
|
org_id: int = Column(Integer, ForeignKey("organization.id"), nullable=False, comment="Organization")
|
2021-08-07 16:14:20 +00:00
|
|
|
body: str = Column(String, nullable=False, comment="Body")
|
|
|
|
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
|
|
|
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
|
2021-08-08 12:23:12 +00:00
|
|
|
replyTo: str = Column(ForeignKey("shout.slug"), nullable=True)
|
|
|
|
versionOf: str = Column(ForeignKey("shout.slug"), nullable=True)
|
|
|
|
tags: str = Column(String, nullable=True)
|
2021-08-19 10:02:28 +00:00
|
|
|
views: int = Column(Integer, default=0)
|
2021-08-20 08:08:32 +00:00
|
|
|
published: bool = Column(Boolean, default=False)
|
|
|
|
publishedAt: str = Column(DateTime, nullable=True)
|
|
|
|
cover: str = Column(String, nullable = True)
|
|
|
|
layout: str = Column(String, nullable = True)
|
|
|
|
authors = relationship(lambda: User, secondary=ShoutAuthors) # NOTE: multiple authors
|
|
|
|
topics = relationship(lambda: Topic, secondary=ShoutTopics)
|