class Member(db.Model): __tablename__ = 'member' id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue()) mobile = db.Column(db.String(11), nullable=False, server_default=db.FetchedValue()) sex = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) avatar = db.Column(db.String(200), nullable=False, server_default=db.FetchedValue()) salt = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue()) reg_ip = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue()) status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue()) created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue()) @property def status_desc(self): return app.config['STATUS_MAPPING'][ str( self.status ) ] @property def sex_desc(self): sex_mapping = { "0":"未知", "1":"男", "2":"女" } return sex_mapping[str(self.sex)]
class Image(db.Model): __tablename__ = 'images' id = db.Column(db.Integer, primary_key=True) file_key = db.Column(db.String(60), nullable=False, server_default=db.FetchedValue()) created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
class OauthMemberBind(db.Model): __tablename__ = 'oauth_member_bind' __table_args__ = (db.Index('idx_type_openid', 'type', 'openid'), ) id = db.Column(db.Integer, primary_key=True) member_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) client_type = db.Column(db.String(20), nullable=False, server_default=db.FetchedValue()) type = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) openid = db.Column(db.String(80), nullable=False, server_default=db.FetchedValue()) unionid = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue()) extra = db.Column(db.Text, nullable=False) updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue()) created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
class Vehiclecat(db.Model): __tablename__ = 'vehiclecat' id = db.Column(db.Integer, primary_key=True, unique=True) name = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue()) weight = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue()) created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue()) @property def status_desc(self): return app.config['STATUS_MAPPING'][ str( self.status ) ]
class StockChangeLog(db.Model): __tablename__ = 'car_change_log' id = db.Column(db.Integer, primary_key=True) food_id = db.Column(db.Integer, nullable=False, index=True) unit = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) total_stock = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) note = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue()) created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
class Menus(db.Model): __tablename__ = "menus" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(32), unique=True) type = db.Column(db.String(64)) order = db.Column(db.SmallInteger, default=0)
class Permission(db.Model): __tablename__ = 'permission' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(32), unique=True, nullable=False) action = db.Column(db.String(128))
class User(UserMixin, db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True, nullable=False) nickname = db.Column(db.String(32, 'utf8mb4_unicode_ci')) email = db.Column(db.String(64, 'utf8mb4_unicode_ci'), nullable=False) password = db.Column(db.String(255, 'utf8mb4_unicode_ci'), nullable=False) password_hash = db.Column(db.String(255)) sign = db.Column(db.String(255, 'utf8mb4_unicode_ci')) status = db.Column(db.Integer) avatars = db.column(db.String(64)) createtime = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue()) updatetime = db.Column(db.DateTime) class Permission(db.Model): __tablename__ = 'permission' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(32), unique=True, nullable=False) action = db.Column(db.String(128)) class Menus(db.Model): __tablename__ = "menus" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(32), unique=True) type = db.Column(db.String(64)) order = db.Column(db.SmallInteger, default=0) def __init__(self, **kwargs): super(User, self).__init__(**kwargs) self.generate_avatar() # self.follow(self) # follow self self.set_role() def __repr__(self): # __repr__方法告诉Python如何打印class对象,方便我们调试使用。 return '<User %r>' % (self.email) # @property #映射用户uid为 flask-login 中get-id 找不到id的问题 # def id (self): # return self.uid @property def password(self): raise AttributeError('密码不是可读属性') @password.setter def password(self, password): self.password_hash = generate_password_hash(password) def verify_password(self, password): return check_password_hash(self.password_hash, password) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False # @property # """必须返回用户的唯一表示符,使用 Unicode 编码字符串""" # def get_id (self): # return self.id # # @login_manager.user_loader # def load_user (user_id): # return User.query.get(int(user_id)) # 用户头像 def generate_avater(self): avater = Identicon filenames = avater.generate(text=self.nickname) self.avatars = filenames[1] db.session.commit()