user_model.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. from datetime import datetime
  2. from typing import Optional
  3. from sqlalchemy import Column, Integer, String, DateTime, Boolean, JSON
  4. from sqlalchemy.orm import relationship
  5. from .base_model import BaseModel, CreateModel, UpdateModel, DeleteModel
  6. class UserModel(BaseModel, CreateModel, UpdateModel, DeleteModel):
  7. """
  8. 用户模型
  9. 对应数据库表: sys_users
  10. """
  11. __tablename__ = 'sys_users'
  12. username = Column(String(50), unique=True, nullable=False, comment='用户名')
  13. password = Column(String(255), nullable=False, comment='密码')
  14. grade = Column(String(20), comment='年级')
  15. preferences = Column(JSON, comment='学习偏好')
  16. goals = Column(JSON, comment='学习目标')
  17. learning_style = Column(String(50), comment='学习风格')
  18. target_score = Column(Integer, comment='目标分数')
  19. # 与角色的一对多关系
  20. roles = relationship('RoleModel',
  21. secondary='sys_user_roles',
  22. back_populates='users')
  23. def __repr__(self):
  24. return f"<User(id={self.id}, username={self.username})>"