1234567891011121314151617181920212223242526272829 |
- from datetime import datetime
- from typing import Optional
- from sqlalchemy import Column, Integer, String, DateTime, Boolean, JSON
- from sqlalchemy.orm import relationship
- from .base_model import BaseModel, CreateModel, UpdateModel, DeleteModel
- class UserModel(BaseModel, CreateModel, UpdateModel, DeleteModel):
- """
- 用户模型
- 对应数据库表: sys_users
- """
- __tablename__ = 'sys_users'
- username = Column(String(50), unique=True, nullable=False, comment='用户名')
- password = Column(String(255), nullable=False, comment='密码')
- grade = Column(String(20), comment='年级')
- preferences = Column(JSON, comment='学习偏好')
- goals = Column(JSON, comment='学习目标')
- learning_style = Column(String(50), comment='学习风格')
- target_score = Column(Integer, comment='目标分数')
- # 与角色的一对多关系
- roles = relationship('RoleModel',
- secondary='sys_user_roles',
- back_populates='users')
- def __repr__(self):
- return f"<User(id={self.id}, username={self.username})>"
|