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 Banner(SurrogatePK,Model): __tablename__ = 'banners' #:横幅标题 title = Column(db.String(100)) #:横幅描述 summary = Column(db.String(200)) image = Column(db.String(200)) alt = Column(db.String(80)) sort = Column(db.Integer()) user = Column(db.Integer, db.ForeignKey('users.id'))
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 ImgUserCongig(CRUDMixin, db.Model): __tablename__ = 'img_user_config_is' id = db.Column(db.Integer, primary_key=True) id_user = db.Column(db.Integer, db.ForeignKey('user_is.id', ondelete='CASCADE')) count = db.Column(db.Integer, default=0) limit = db.Column(db.Integer, default=20) @property def to_json(self): """Return object data in easily serializable format""" return { 'id': self.id, 'id_user': self.id_user, 'count': self.count, "limit": self.limit } def __repr__(self): return f"<Img-User-Config-ID:{self.id} id_user: {self.id_user} >"
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 PhotoImage(SurrogatePK,Model): __tablename__ = 'photo_images' path = Column(db.String(200)) photo = Column(db.Integer, db.ForeignKey('photos.id'))
#coding=utf-8 from main.database import Column, Model, SurrogatePK, db, reference_col, relationship from main.extensions import bcrypt, rbac from flask_rbac import RoleMixin class Permission: ADMINISTER = 0x8000 #管理员权限 roles_parents = db.Table( 'roles_parents', db.Column('role_id', db.Integer, db.ForeignKey('roles.id')), db.Column('parent_id', db.Integer, db.ForeignKey('roles.id'))) @rbac.as_role_model class Role(SurrogatePK, Model, RoleMixin): """A role for a user.""" __tablename__ = 'roles' name = db.Column(db.String(80)) parents = db.relationship( 'Role', secondary=roles_parents, primaryjoin=("Role.id == roles_parents.c.role_id"), secondaryjoin=("Role.id == roles_parents.c.parent_id"), backref=db.backref('children', lazy='dynamic')) def __init__(self, name):
import datetime from main.database import db, CRUDMixin from main.tags.models import Tag article_tags_meta = db.Table( 'article_tags', db.Model.metadata, db.Column('article_id_2', db.Integer, db.ForeignKey('article_model.id')), db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')), extend_existing=True ) class Articles(CRUDMixin, db.Model): __tablename__ = 'article_model' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String, name="Название", nullable=False) url = db.Column(db.String, name="Url", nullable=False) anons = db.Column(db.Text, name="Анонс") date = db.Column(db.DateTime, default=datetime.datetime.now) tags = db.relationship(Tag, secondary=article_tags_meta) author = db.Column(db.String, name="Автор") text = db.Column(db.Text, name="Результат") image = db.Column(db.String, nullable=False)
#coding=utf-8 from itsdangerous import TimedJSONWebSignatureSerializer as Serializer from flask import current_app # from flask_login import UserMixin from flask_rbac import UserMixin from main.database import Column, Model, SurrogatePK, db, reference_col, relationship from main.extensions import bcrypt, rbac import datetime from main.models.recommend import Recommend from main.models.buys_car import BuysCar users_roles = db.Table( 'users_roles', db.Column('user_id', db.Integer, db.ForeignKey('users.id')), db.Column('role_id', db.Integer, db.ForeignKey('roles.id'))) @rbac.as_user_model class User(SurrogatePK, Model, UserMixin): """用户表. 表名称:users 列名称: - username:用户名 - password:密码 ,hashed password - created_at:创建时间 - name:姓名 - active:是否激活。默认false