core/orm/author.py

47 lines
1.7 KiB
Python
Raw Normal View History

2023-10-23 14:47:11 +00:00
from datetime import datetime
from sqlalchemy import JSON as JSONType
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
2023-10-25 16:55:30 +00:00
from services.db import Base
2023-10-23 14:47:11 +00:00
class AuthorRating(Base):
__tablename__ = "author_rating"
id = None # type: ignore
rater = Column(ForeignKey("author.id"), primary_key=True, index=True)
author = Column(ForeignKey("author.id"), primary_key=True, index=True)
value = Column(Integer)
@staticmethod
def init_table():
pass
class AuthorFollower(Base):
__tablename__ = "author_follower"
id = None # type: ignore
follower = Column(ForeignKey("author.id"), primary_key=True, index=True)
author = Column(ForeignKey("author.id"), primary_key=True, index=True)
createdAt = Column(DateTime, nullable=False, default=datetime.now)
auto = Column(Boolean, nullable=False, default=False)
class Author(Base):
__tablename__ = "author"
2023-10-25 16:55:30 +00:00
user = Column(String, nullable=False) # unbounded link with authorizer's User type
2023-10-23 14:47:11 +00:00
bio = Column(String, nullable=True, comment="Bio") # status description
about = Column(String, nullable=True, comment="About") # long and formatted
2023-10-25 16:55:30 +00:00
pic = Column(String, nullable=True, comment="Userpic")
2023-10-23 14:47:11 +00:00
name = Column(String, nullable=True, comment="Display name")
slug = Column(String, unique=True, comment="Author's slug")
2023-10-25 16:55:30 +00:00
2023-10-23 14:47:11 +00:00
createdAt = Column(DateTime, nullable=False, default=datetime.now)
lastSeen = Column(DateTime, nullable=False, default=datetime.now) # Td se 0e
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
2023-10-25 16:55:30 +00:00
2023-10-23 14:47:11 +00:00
links = Column(JSONType, nullable=True, comment="Links")
ratings = relationship(AuthorRating, foreign_keys=AuthorRating.author)