MarseyWorld/files/classes/award.py

41 lines
1.2 KiB
Python
Raw Normal View History

2022-05-04 23:09:46 +00:00
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
from files.helpers.lazy import lazy
from files.helpers.const import *
class AwardRelationship(Base):
__tablename__ = "award_relationships"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
submission_id = Column(Integer, ForeignKey("submissions.id"))
comment_id = Column(Integer, ForeignKey("comments.id"))
kind = Column(String)
awarded_utc = Column(Integer)
2022-08-18 20:10:58 +00:00
granted = Column(Boolean)
2022-05-04 23:09:46 +00:00
user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards")
post = relationship("Submission", primaryjoin="AwardRelationship.submission_id==Submission.id", back_populates="awards")
comment = relationship("Comment", primaryjoin="AwardRelationship.comment_id==Comment.id", back_populates="awards")
2022-05-04 23:09:46 +00:00
def __repr__(self):
return f"<AwardRelationship(id={self.id})>"
2022-05-04 23:09:46 +00:00
@property
@lazy
def type(self):
2022-08-30 01:13:43 +00:00
if self.kind in AWARDS: return AWARDS[self.kind]
else: return HOUSE_AWARDS[self.kind]
2022-05-04 23:09:46 +00:00
@property
@lazy
def title(self):
return self.type['title']
@property
@lazy
def class_list(self):
return self.type['icon']+' '+self.type['color']