class User(UserMixin, db.Model): __tablename__ = 'users' # id自增 id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 登录名,不允许重复 name = db.Column(db.String(16), unique=True, nullable=False, index=True) password = db.Column(db.String(32), nullable=False) phone_number = db.Column(db.String(16), unique=True, nullable=True) email = db.Column(db.String(32), nullable=False) def __init__(self, name, password, phone_number, email): self.name = name self.password = password self.phone_number = phone_number self.email = email def get_id(self): return unicode(self.id) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False
class User(db.Model): id = db.Column(db.Integer, primary_key=True) fullName = db.Column(db.String(100)) CC = db.Column(db.String(10), unique=True) phone = db.Column(db.String(15)) password = db.Column(db.Text) def __init__(self, fullName, CC, phone, password): self.fullName = fullName self.CC = CC self.phone = phone self.password = password
class Borrower(db.Model): id = db.Column(db.Integer, primary_key=True) fullname = db.Column(db.String(100)) CC = db.Column(db.String(10), unique=True) phone = db.Column(db.String(15)) amount = db.Column(db.Float(15)) percentage = db.Column(db.Float(3)) months = db.Column(db.Integer) def __init__(self, fullname, CC, phone, amount, percentage, months): self.fullname = fullname self.CC = CC self.phone = phone self.amount = amount self.percentage = percentage self.months = months
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(80), unique=False, nullable=False) # будем хранить хэш пароля def __repr__(self): return '<User {} {}>'.format(self.id, self.username) @staticmethod def add(username, password): user = User(username=username, password=password) db.session.add(user) db.session.commit() @staticmethod def delete(obj): db.session.delete(obj) db.session.commit()
class Key(db.Model): __tablename__ = 'api_tokens' # id自增 id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 用户名加app名字作为主键 username = db.Column(db.String(16), primary_key=True, nullable=False) app_name = db.Column(db.String(16), nullable=False, index=True) app_type = db.Column(db.String(16), nullable=False) api_key = db.Column(db.String(32), unique=True, nullable=False) api_secret = db.Column(db.String(32), nullable=False) def __init__(self, name, app, app_type, api_key, api_secret): self.username = name self.app_name = app self.app_type = app_type self.api_key = api_key self.api_secret = api_secret def get_id(self): return unicode(self.id) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def to_dict(self): return dict({ 'app_name': self.app_name, 'api_key': self.api_key, 'api_secret': self.api_secret })