class UserInfo(db.Model): """ 用户信息表 """ account = db.Column(db.String(255), primary_key=True) name = db.Column(db.String(255), nullable=False) password = db.Column(db.VARBINARY(255), nullable=False) # 貌似加密后最长128 # last_login = db.Column(db.DateTime, nullable=False) modified = db.Column(db.DateTime, nullable=False, default=datetime.now) create = db.Column(db.DateTime, nullable=False, default=datetime.now) roles = db.relationship('Role', cascade='save-update,merge,delete', secondary=user_info_role, backref=('user_infos')) user_status = db.relationship('UserStatus', cascade='save-update,merge,delete', secondary=user_info_user_status, backref=('user_infos')) user_info_user_notification = db.relationship('UserNotification', cascade='all', secondary=user_info_user_notification, backref=('user_infos')) def lock(self): # self.locked=True self.roles[0] = Role.query.filter_by(name='Locked').first() db.session.commit() def unlock(self): # self.locked=False self.roles[0] = Role.query.filter_by(name='User').first() db.session.commit()
class Role(db.Model): name = db.Column(db.String(255), primary_key=True) modified = db.Column(db.DateTime, nullable=False, default=datetime.now) create = db.Column(db.DateTime, nullable=False, default=datetime.now) authorities = db.relationship('Authority', cascade='save-update,merge,delete', secondary=role_authority, backref=('roles'))
class UserNotification(db.Model): """ 提醒消息 """ id = db.Column(db.Integer, primary_key=True) message = db.Column(db.Text) is_read = db.Column(db.Boolean, default=False) modified = db.Column(db.DateTime, nullable=False, default=datetime.now) create = db.Column(db.DateTime, nullable=False, default=datetime.now)
class DimensionNoteReading(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=False) origin_name_book = db.Column(db.String(255), nullable=False) # 书名 origin_author_book = db.Column(db.String(255), nullable=False) # 作者 origin_page_book = db.Column(db.String(255), nullable=False) # 页码 # note = db.Column(db.String(512), nullable=False) # 摘录 note = db.Column(db.Text, nullable=False) # 摘录 category = db.Column(db.String(255), nullable=False) # 类别 modified = db.Column(db.DateTime, nullable=False, default=datetime.now) create = db.Column(db.DateTime, nullable=False, default=datetime.now)
class UserStatus(db.Model): """ 用户状态表 """ auto_id = db.Column(db.Integer, primary_key=True, autoincrement=True) token = db.Column(db.String(255), nullable=False) current_page = db.Column(db.String(255), nullable=False) last_login = db.Column(db.DateTime, nullable=False,default=datetime.now) modified = db.Column(db.DateTime, nullable=False,default=datetime.now) create = db.Column(db.DateTime, nullable=False,default=datetime.now)
class LogRequestHttp(db.Model): id = db.Column(db.Integer, autoincrement=True, primary_key=True) ip_original = db.Column(db.String(128), nullable=False) ip_destination = db.Column(db.String(128), nullable=False) host = db.Column(db.String(128), nullable=False) uri = db.Column(db.String(1024)) method = db.Column(db.String(10), nullable=False) request_data = db.Column(db.String(1024)) user_agent = db.Column(db.String(256)) port_destination = db.Column(db.Integer) referrer = db.Column(db.String(255)) create = db.Column(db.DateTime, nullable=False, default=datetime.now)
class Authority(db.Model): name = db.Column(db.String(255), primary_key=True) resource_code = db.Column(db.Integer, nullable=False) modified = db.Column(db.DateTime, nullable=False, default=datetime.now) create = db.Column(db.DateTime, nullable=False, default=datetime.now)
from blog.models.base import db from blog.models.role import Role from datetime import datetime user_info_role = db.Table('user_info_role', db.Column('user_info_account', db.String(255), db.ForeignKey('user_info.account'), primary_key=True), db.Column('role_name', db.String(255), db.ForeignKey('role.name'), primary_key=True), db.Column('modified', db.DateTime, db.ColumnDefault(datetime.now), nullable=False), db.Column('create', db.DateTime, db.ColumnDefault(datetime.now), nullable=False) ) user_info_user_status = db.Table('user_info_user_status', db.Column('user_info_account', db.String(255), db.ForeignKey('user_info.account'), primary_key=True), db.Column('user_status_auto_id', db.Integer, db.ForeignKey('user_status.auto_id'), primary_key=True), db.Column('modified', db.DateTime, db.ColumnDefault(datetime.now), nullable=False), db.Column('create', db.DateTime, db.ColumnDefault(datetime.now), nullable=False) ) user_info_user_notification = db.Table('user_info_user_notification', db.Column('user_info_account', db.String(255), db.ForeignKey('user_info.account')), db.Column('user_notification_id', db.Integer, db.ForeignKey('user_notification.id')), db.Column('modified', db.DateTime, default=datetime.now, nullable=False), db.Column('create', db.DateTime, default=datetime.now, nullable=False)) class UserInfo(db.Model):
class DimensionQuote(db.Model): origin = db.Column(db.String(255), nullable=False) quote = db.Column(db.String(255), nullable=False) modified = db.Column(db.DateTime, nullable=False,default=datetime.now) create = db.Column(db.DateTime, nullable=False,default=datetime.now)
from blog.models.base import db from datetime import datetime role_authority = db.Table( 'role_authority', db.Column('role_name', db.String(255), db.ForeignKey('role.name'), primary_key=True), db.Column('authority_name', db.String(255), db.ForeignKey('authority.name'), primary_key=True), db.Column('modified', db.DateTime, db.ColumnDefault(datetime.now), nullable=False), db.Column('create', db.DateTime, db.ColumnDefault(datetime.now))) class Role(db.Model): name = db.Column(db.String(255), primary_key=True) modified = db.Column(db.DateTime, nullable=False, default=datetime.now) create = db.Column(db.DateTime, nullable=False, default=datetime.now) authorities = db.relationship('Authority', cascade='save-update,merge,delete', secondary=role_authority, backref=('roles'))