Models.py 851 B

1234567891011121314151617181920212223242526
  1. from sqlalchemy import Boolean, Column, Date, DateTime, Integer, String
  2. from sqlalchemy.orm import declarative_base
  3. Base = declarative_base()
  4. class UserModel(Base):
  5. __tablename__ = "rest_user"
  6. id = Column(Integer, primary_key=True, autoincrement=True, )
  7. name = Column(String)
  8. birthday = Column(Date)
  9. insys = Column(Boolean)
  10. idrole = Column(Integer)
  11. lastlogintime = Column(DateTime)
  12. email = Column(String)
  13. password = Column(String)
  14. def as_dict(self):
  15. return {c.name: getattr(self, c.name) for c in self.__table__.columns}
  16. class RoleModel(Base):
  17. __tablename__ = 'rest_role'
  18. id = Column(Integer, primary_key=True, autoincrement=True, )
  19. name = Column(String, unique=True, nullable=False)
  20. def as_dict(self):
  21. return {c.name: getattr(self, c.name) for c in self.__table__.columns}