class User(CRUDMixin, db.Model): __tablename__ = 'user_is' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30)) password = db.Column(db.String(255)) date_create = db.Column(db.DateTime(), default=datetime.now()) @property def to_json(self): """Return object data in easily serializable format""" return { 'id': self.id, 'name': self.name, 'date_create': self.date_create.strftime("%A, %d. %B %Y %I:%M%p"), } def check_encrypted_password(self, p): return pwd_context.verify(p + current_app.config['SALT'], self.password) @classmethod def encrypt_password(cls, password): return pwd_context.encrypt(password + current_app.config['SALT']) @classmethod def get_by_name(cls, name): return cls.query.filter_by(name=name).first() def __repr__(self): return f"<User-ID:{self.id} NAME: {self.name} >"
class Access(SurrogatePK, Model): __tablename____ = "access" __table_args__ = {'comment': '权限表'} url = Column(db.String(200), nullable=False, comment="路由正则匹配") name = Column(db.String(100), comment="节点名称") status = Column(db.Integer(), comment="状态", default=1) sort = Column(db.Integer(), comment="排序", default=100) is_del = Column(db.Boolean(), comment="是否删除", default=False) create_at = Column(db.DateTime(), default=dt.datetime.now, comment='创建时间') user_id = Column(db.Integer(), comment="创建用户") @classmethod def insert_data(cls, form): status = True if form.get("status") else False sort = form.get("sort") if form.get("sort") else 100 is_del = True if form.get("is_del") else False is_url = form.get("is_url") if form.get("is_url") else '' pid = form.get("pid") if form.get("pid") else 0 is_del = True if form.get("pid") else False cls.create(name=form.get("name"), url=form.get("url"), status=status, sort=sort, is_del=is_del, user_id=current_user.id)
class Role(SurrogatePK, Model): """A role for a user.""" __tablename__ = "roles" name = Column(db.String(80), nullable=False) pid = Column(db.Integer(),comment="上级") remark = Column(db.String(100),comment="描述") sort = Column(db.Integer(),server_default='100',comment='排序') create_at = Column(db.DateTime(),comment='创建时间',default=dt.datetime.now) is_del = Column(db.Boolean(),comment="是否删除",default=False) def __init__(self, name, **kwargs): """Create instance.""" db.Model.__init__(self, name=name, **kwargs) def __repr__(self): """Represent instance as a unique string.""" return f"<Role({self.name})>" @classmethod def insert_data(cls,form): sort = form.get("is_url") if form.get("is_url") else 100 is_url = True if form.get("is_url") else '' pid = True if form.get("pid") else 0 is_del = True if form.get("pid") else False cls.create( name = form.get("name"), pid = pid, remark = form.get("remark"), sort = sort, is_del = is_del, )
class Img(CRUDMixin, db.Model): __tablename__ = 'img_is' id = db.Column(db.Integer, primary_key=True) path = db.Column(db.String()) name = db.Column(db.String()) old_size = db.Column(db.String()) new_size = db.Column(db.String()) id_user = db.Column(db.Integer, db.ForeignKey('user_is.id', ondelete='CASCADE')) date_create = db.Column(db.DateTime(), default=datetime.now()) @property def to_json(self): """Return object data in easily serializable format""" return { 'id': self.id, 'path': self.path.split("main")[-1], 'name': self.name, 'old_size': self.old_size, 'new_size': self.new_size, "id_user": self.id_user, "date_create": self.date_create.strftime("%d.%m.%Y %H:%M:%S"), } def __repr__(self): return f"<Img-ID:{self.id} NAME: {self.name} >"
class Photo(SurrogatePK,Model): __tablename__ = 'photos' #:图集标题 title = Column(db.String(80),nullable=False) #:图集描述 summary = Column(db.String(500)) #:关键字 key = Column(db.String(80)) #:关键描述 word = Column(db.String(500)) #:拍摄时间 photos_date = Column(db.DateTime(),default=dt.datetime.now) #:创建时间 creation_date = Column(db.DateTime(),default=dt.datetime.now) #缩略图 #保存路径 image = Column(db.String(200)) image_alt = Column(db.String(80)) #:浏览次数 count = Column(db.Integer,default=100) #:是否显示 is_enable = Column(db.Boolean,default=True) #图集属性 attr_id = db.Column(db.Integer,db.ForeignKey('content_attrs.id')) #图集照片 photo_image = db.relationship('PhotoImage', backref='photo_images',lazy='dynamic') #附加字段,附加字段值 attach_key = Column(db.String(200)) attach_value = Column(db.String(500)) #静态内容,用“|”号隔开 static_context = Column(db.UnicodeText) user = reference_col('users') category = reference_col('categorys')
class Category(SurrogatePK,Model): __tablename__ = 'categorys' #:栏目标题 title = Column(db.String(80),nullable=False) #:栏目描 summary = Column(db.String(100)) #:关键字 key = Column(db.String(80)) #:关键描述 word = Column(db.String(500)) #:创建时间 creation_date = Column(db.DateTime(),default=dt.datetime.now) #:排序 sort = Column(db.Integer,default=100) #:是否显示 is_enable = Column(db.Boolean,default=True) #:首页展示顺序 main_sort = Column(db.Integer,default=100) #:栏目静态内容 static_content = Column(db.UnicodeText) #:附加内容 attach_value = Column(db.UnicodeText) #状态 0用户删除不做正式删除 1正常 state = Column(db.Integer,default=1) attr_id = reference_col('category_attrs') #:所属用户栏目 user = reference_col('users') #:引用自身无限级分类 parent_id = reference_col('categorys') children = relationship("Category",lazy="joined",join_depth=2,post_update=True) #所属文章 article = relationship('Article', backref='categorys',lazy='dynamic') #所属图集 photo = relationship('Photo', backref='categorys',lazy='dynamic') #栏目静态内容 static_context = relationship('StaticContext', backref='categorys',lazy='dynamic') def __repr__(self): return '<CategoryAttr({name!r})>'.format(name=self.title)
class UserMark(SurrogatePK,Model): __tablename__ = 'usermarks' #用户姓名 name = Column(db.String(80)) #联系电话 phone = Column(db.String(20)) #留言内容 content = Column(db.UnicodeText) #用户头像 image = Column(db.String(200)) #:附加段、值 attach_key = Column(db.String(200)) attach_value = Column(db.String(500)) creation_date = Column(db.DateTime(),default=dt.datetime.now) user_mark_type = Column(db.Integer, db.ForeignKey('user_mark_types.id')) user = reference_col('users')
class Article(SurrogatePK,Model): __tablename__ = 'articles' #:文章标题 title = Column(db.String(80),nullable=False) #:作者 author = Column(db.String(80)) #:来源 source = Column(db.String(80)) #:文章描述 summary = Column(db.String(500)) #:关键字 key = Column(db.String(80)) #:关键描述 word = Column(db.String(500)) #:创建时间 creation_date = Column(db.DateTime(),default=dt.datetime.now) #:是否显示 is_enable = Column(db.Boolean,default=True) #:内容 content = Column(db.UnicodeText) #:浏览次数 count = Column(db.Integer,default=100) #缩略图 #保存路径 image = Column(db.String(200)) image_alt = Column(db.String(80)) #文章属性 #附加字段,附加字段值 attach_key = Column(db.String(200)) attach_value = Column(db.String(500)) #静态内容,用“|”号隔开 static_context = Column(db.UnicodeText) attr_id = reference_col('content_attrs') category = reference_col('categorys') user = reference_col('users')