La version 5 de Planète Casio. Regroupe le forum, les programmes, les tutoriel, les sprites et tous les autres outils développés par nos soins.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3KB

  1. from app import db
  2. # Trophy: Achievements granted to users for performing specific actions
  3. class Trophy(db.Model):
  4. __tablename__ = 'trophy'
  5. # Trophy ID and type (polymorphic discriminator)
  6. id = db.Column(db.Integer, primary_key=True)
  7. type = db.Column(db.String(20))
  8. __mapper_args__ = {
  9. 'polymorphic_identity': __tablename__,
  10. 'polymorphic_on': type
  11. }
  12. # Trophy name (in French)
  13. name = db.Column(db.Unicode(64), index=True)
  14. owners = db.relationship('Member', secondary=lambda: TrophyMember,
  15. back_populates='trophies')
  16. def __init__(self, name):
  17. self.name = name
  18. def __repr__(self):
  19. return f'<Trophy: {self.name}>'
  20. # Title: Rare trophies that can be displayed along one's name
  21. class Title(Trophy):
  22. __tablename__ = 'title'
  23. __mapper_args__ = {'polymorphic_identity': __tablename__}
  24. id = db.Column(db.Integer, db.ForeignKey('trophy.id'), primary_key=True)
  25. css = db.Column(db.UnicodeText)
  26. def __init__(self, name, css=""):
  27. self.name = name
  28. self.css = css
  29. def __repr__(self):
  30. return f'<Title: {self.name}>'
  31. # Many-to-many relation for users earning trophies
  32. TrophyMember = db.Table('trophy_member', db.Model.metadata,
  33. db.Column('tid', db.Integer, db.ForeignKey('trophy.id')),
  34. db.Column('uid', db.Integer, db.ForeignKey('member.id')))