Files
core/orm/community.py

36 lines
1.2 KiB
Python
Raw Normal View History

2021-08-27 00:14:20 +03:00
from datetime import datetime
from sqlalchemy import Column, String, ForeignKey, DateTime
from orm.base import Base, local_session
2021-08-27 00:14:20 +03:00
class CommunityFollower(Base):
__tablename__ = 'community_followers'
id = None
follower = Column(ForeignKey('user.slug'), primary_key = True)
community = Column(ForeignKey('community.slug'), primary_key = True)
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
2021-08-27 00:14:20 +03:00
class Community(Base):
__tablename__ = 'community'
2021-08-27 00:14:20 +03:00
name: str = Column(String, nullable=False, comment="Name")
2022-07-14 16:41:53 +03:00
slug: str = Column(String, nullable = False, unique=True, comment="Slug")
2021-08-28 13:13:50 +03:00
desc: str = Column(String, nullable=False, default='')
pic: str = Column(String, nullable=False, default='')
2021-08-27 00:14:20 +03:00
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
createdBy: str = Column(ForeignKey("user.slug"), nullable=False, comment="Author")
@staticmethod
def init_table():
with local_session() as session:
2021-12-16 22:16:59 +03:00
default = session.query(Community).filter(Community.slug == "discours").first()
2021-12-10 16:52:55 +03:00
if not default:
default = Community.create(
2021-12-16 14:34:16 +03:00
name = "Дискурс",
slug = "discours",
2022-07-14 16:41:53 +03:00
createdBy = "discours"
2021-12-10 16:52:55 +03:00
)
Community.default_community = default