models.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 Region(Base):
  8. """Model for region"""
  9. __tablename__ = 'region'
  10. id = Column(Integer, primary_key=True)
  11. name = Column(String)
  12. class State(Base):
  13. """Model for state"""
  14. __tablename__ = 'state'
  15. id = Column(Integer, primary_key=True)
  16. name = Column(String)
  17. class StateRegion(Base):
  18. """Model for state region"""
  19. __tablename__ = 'state_region'
  20. state_id = Column(Integer, ForeignKey('state.id'), primary_key=True)
  21. region_id = Column(Integer, ForeignKey('region.id'), primary_key=True)
  22. from_date_time = Column(DateTime, primary_key=True)
  23. until_date_time = Column(DateTime)
  24. region = relationship(
  25. 'Region',
  26. backref=backref('state_regions', lazy='dynamic')
  27. )
  28. state = relationship(
  29. 'State',
  30. backref=backref('state_regions', lazy='dynamic')
  31. )