core/orm/comment.py

33 lines
1.2 KiB
Python
Raw Normal View History

2021-09-03 16:01:31 +00:00
from typing import List
from datetime import datetime
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
2021-09-05 08:56:15 +00:00
from sqlalchemy.orm import relationship
2021-09-03 16:01:31 +00:00
from orm.base import Base
class CommentRating(Base):
__tablename__ = "comment_rating"
id = None
rater_id = Column(ForeignKey('user.id'), primary_key = True)
comment_id = Column(ForeignKey('comment.id'), primary_key = True)
ts: str = Column(DateTime, nullable=False, default = datetime.now, comment="Timestamp")
value = Column(Integer)
class Comment(Base):
2021-09-05 08:56:15 +00:00
__tablename__ = 'comment'
2021-09-03 16:01:31 +00:00
2021-09-05 08:56:15 +00:00
author: int = Column(ForeignKey("user.id"), nullable=False, comment="Sender")
body: str = Column(String, nullable=False, comment="Body")
createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
deletedBy = Column(ForeignKey("user.id"), nullable=True, comment="Deleted by")
shout: int = Column(ForeignKey("shout.id"), nullable=True, comment="Shout ID")
2021-09-03 16:01:31 +00:00
ratings = relationship(CommentRating, foreign_keys=CommentRating.comment_id)
old_id: str = Column(String, nullable = True)
2021-09-05 08:56:15 +00:00
2021-09-03 16:01:31 +00:00
2021-09-05 08:56:15 +00:00
# TODO: work in progress, udpate this code