open-law/app/models/comment.py

34 lines
1.0 KiB
Python
Raw Normal View History

2023-04-21 12:58:47 +00:00
from app import db
from app.models.utils import BaseModel
class Comment(BaseModel):
__tablename__ = "comments"
2023-04-27 13:17:25 +00:00
# need to redeclare id to use it in the parent relationship
2023-04-21 12:58:47 +00:00
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.Text, unique=False, nullable=False)
marked = db.Column(db.Boolean, default=False)
2023-04-27 13:17:25 +00:00
included_with_interpretation = db.Column(db.Boolean, default=False)
2023-04-21 12:58:47 +00:00
# Foreign keys
user_id = db.Column(db.ForeignKey("users.id"))
2023-04-27 13:17:25 +00:00
parent_id = db.Column(db.ForeignKey("comments.id"))
2023-04-21 12:58:47 +00:00
interpretation_id = db.Column(db.ForeignKey("interpretations.id"))
# Relationships
user = db.relationship("User")
children = db.relationship(
"Comment", backref=db.backref("parent", remote_side=[id]), viewonly=True
)
interpretation = db.relationship("Interpretation")
votes = db.relationship("CommentVote")
tags = db.relationship(
"Tag",
secondary="comment_tags",
back_populates="comments",
)
def __repr__(self):
return f"<{self.id}: {self.text[:20]}>"