class User(db.Document, UserMixin): meta = { "collection": "user", # 表名 "ordering": ["-id"], # id "strict": True # 自动修改表内容 } username = db.StringField() # 帐号 password_hash = db.StringField() # 密码 nickname = db.StringField() # 用户名 user_course_code = db.SortedListField( db.EmbeddedDocumentField(UserCourseCode), ordering="course_id", reverse=False) user_project_code = db.SortedListField( db.EmbeddedDocumentField(UserProjectCode), ordering="project_id", reverse=False) superuser = db.BooleanField(default=False) # 是否为管理员,后续可以用来进入后台(未实现) # 密码加密 def hash_password(self, password): self.password_hash = generate_password_hash(password) self.save() # 密码验证 def verify_password(self, password): return check_password_hash(self.password_hash, password)
class ProjectModel(db.Document): _id = db.ObjectIdField() project_id = db.IntField() title = db.StringField() text = db.StringField() test = db.StringField() meta = {"collection": "project", "strict": "False"}
class EmbeddedModuleModal(db.EmbeddedDocument): _id = db.ObjectIdField() module_name = db.StringField() order = db.IntField(unique_with='module_name') sub_modules = db.SortedListField(db.EmbeddedDocumentField(SubModule), ordering="sub_order", reverse=False)
class ModuleModel(db.Document): _id = db.ObjectIdField() module_name = db.StringField() order = db.IntField(unique_with='module_name') sub_modules = db.SortedListField(db.EmbeddedDocumentField(SubModule), ordering="sub_order", reverse=False) meta = {"collection": "module", "strict": "False", 'ordering': ['-order']}
class CourseModel(db.Document): _id = db.ObjectIdField() course_id = db.IntField() title = db.StringField() text = db.StringField() goal = db.StringField() frame_head = db.StringField() frame_foot = db.StringField() code = db.StringField() concept = db.SortedListField( db.ReferenceField(Concept, reverse_delete_rule=PULL)) meta = {"collection": "course", "strict": "False"}
class UserProjectCode(db.EmbeddedDocument): project_id = db.StringField() html_code = db.StringField() css_code = db.StringField() js_code = db.StringField() add_js = db.SortedListField(db.StringField())
class UserCourseCode(db.EmbeddedDocument): course_id = db.StringField() code = db.StringField()
class Concept(db.Document): _id = db.ObjectIdField() name = db.StringField(unique=True)
class Unit(db.EmbeddedDocument): unit_id = db.ObjectIdField() unit_title = db.StringField() unit_order = db.IntField() unit_type = db.StringField()
class SubModule(db.EmbeddedDocument): sub_id = db.ObjectIdField() sub_order = db.IntField() type = db.StringField()