models.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Database models"""
  2. from sqlalchemy import Column, ForeignKey, Integer, String, \
  3. SmallInteger, DateTime, BigInteger, Date
  4. from sqlalchemy.orm import relationship, backref
  5. from sqlalchemy.ext.declarative import declarative_base
  6. Base = declarative_base()
  7. class Player(Base):
  8. """Model for player"""
  9. __tablename__ = 'player'
  10. id = Column(BigInteger, primary_key=True)
  11. name = Column(String)
  12. nation = Column(String)
  13. registration_date = Column(Date)
  14. class State(Base):
  15. """Model for state"""
  16. __tablename__ = 'state'
  17. id = Column(Integer, primary_key=True)
  18. name = Column(String)
  19. class Department(Base):
  20. """Model for department"""
  21. __tablename__ = 'department'
  22. id = Column(Integer, primary_key=True)
  23. name = Column(String)
  24. department_type = Column(Integer)
  25. state_id = Column(Integer, ForeignKey('state.id'))
  26. state = relationship(
  27. 'State',
  28. backref=backref('elections', lazy='dynamic')
  29. )
  30. class DepartmentStat(Base):
  31. """Model for departent stat"""
  32. __tablename__ = 'department_stat'
  33. id = Column(Integer, primary_key=True)
  34. date_time = Column(DateTime)
  35. points = Column(SmallInteger)
  36. player_id = Column(BigInteger, ForeignKey('player.id'))
  37. player = relationship(
  38. 'Player',
  39. backref=backref('department_stats', lazy='dynamic')
  40. )
  41. department_id = Column(Integer, ForeignKey('department.id'))
  42. department = relationship(
  43. 'Department',
  44. backref=backref('department_stats', lazy='dynamic')
  45. )