class Accounts(db.Model): id = db.Column(db.Integer, primary_key=True) encrypted_social_media = db.Column(db.String(20)) encrypted_username = db.Column(db.String(30)) encrypted_password = db.Column(db.String(30)) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) # getter and setter (encrypting values before saving to database) @property def social_media(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_social_media) @property def username(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_username) @property def password(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_password) @social_media.setter def social_media(self, value): self.encrypted_social_media = Encryption.encrypt(ENCRYPTION_KEY, value) @username.setter def username(self, value): self.encrypted_username = Encryption.encrypt(ENCRYPTION_KEY, value) @password.setter def password(self, value): self.encrypted_password = Encryption.encrypt(ENCRYPTION_KEY, value)
class Dog(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(30), nullable=False, unique=True) place = db.Column(db.String(50), default="杭州户口") def to_dict(self): data = {"id": self.id, "name": self.name, "place": self.place} return data
class Todo(db.Model): __tablename__ = 'todo' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20)) description = db.Column(db.String(100)) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return 'Id: {}, name: {}'.format(self.id, self.name)
class User(db.Model): #use UserMixin is ok too __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(32), unique=True) email = db.Column(db.String(64), unique=True) password = db.Column(db.String(32)) about_me = db.Column(db.String(64)) register_time = db.Column(db.DateTime, default=datetime.now()) avatar = db.Column(db.String(32)) posts = db.relationship('Post', backref='user', lazy='dynamic') def __init__(self, name, email, password): self.name = name self.email = email self.password = password self.authentication = False def __repr__(self): return '<User:%s>' % self.name def get_user(self, name): return User.query.filter_by(name=name).first() def is_authenticated(self): return True if self.authentication else False def is_active(self): return True def is_anonymous(self): return (True if self.authentication else False) def get_id(self): return (self.id) def checkPassword(self, InPassword): if InPassword == self.password: self.authentication = True return True else: return False def checkNameRepeat(self, inname): return True if inname == self.name else False def checkEmailRepeat(self, inemail): return True if inemail == self.email else False def checkReapt(self, name, email): return self.checkEmailRepeat(email) and self.checkNameRepeat(name)
class Account(db.Model, BaseModel): __tablename__ = 'accounts' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(150), unique=True, nullable=False) phone = db.Column(db.String(12), unique=False, nullable=True) malls = db.relationship('Mall') creation_date = db.Column(db.DateTime, default=now, nullable=False) last_modification_date = db.Column(db.DateTime, default=now, onupdate=now, nullable=False) def __init__(self, name, phone=None, **kwargs): self.name = name self.phone = phone
class User(db.Model): """Basic user model """ id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) active = db.Column(db.Boolean, default=True) def __init__(self, **kwargs): super(User, self).__init__(**kwargs) self.password = pwd_context.hash(self.password) def __repr__(self): return "<User %s>" % self.username
class Post(db.Model): __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) send_time = db.Column(db.DateTime, default=datetime.now()) body = db.Column(db.String(128)) post_like_person_ids = db.relationship('PostLike', backref='post', lazy='dynamic', foreign_keys='PostLike.post_id', cascade="all, delete-orphan", passive_deletes=True) all_comments = db.relationship( 'Comment', backref='post', lazy='dynamic', foreign_keys='Comment.post_id', #class.filed to assignment cascade="all, delete-orphan", passive_deletes=True) def __init__(self, user_id, body): self.body = body self.user_id = user_id def __repr__(self): return '<Post:%s>' % self.body
class Book(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(20), ) tags = db.relationship("Tag", secondary=tags, backref=db.backref("books", lazy=True), lazy=True)
class Unit(db.Model, BaseModel): __tablename__ = 'units' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(150), unique=True, nullable=False) manager = db.Column(db.String(150), unique=False, nullable=True) mall_id = db.Column(db.Integer, db.ForeignKey("malls.id", ondelete='SET NULL')) creation_date = db.Column(db.DateTime, default=now, nullable=False) last_modification_date = db.Column(db.DateTime, default=now, onupdate=now, nullable=False) def __init__(self, name, manager=None, mall_id=None, **kwargs): self.name = name self.manager = manager self.manager = mall_id
class Mall(db.Model, BaseModel): __tablename__ = 'malls' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(150), unique=True, nullable=False) address = db.Column(db.String(300), unique=False, nullable=True) account_id = db.Column(db.Integer, db.ForeignKey("accounts.id", ondelete='SET NULL')) units = db.relationship('Unit', lazy='joined') creation_date = db.Column(db.DateTime, default=now, nullable=False) last_modification_date = db.Column(db.DateTime, default=now, onupdate=now, nullable=False) def __init__(self, name, address=None, account_id=None, **kwargs): self.name = name self.address = address self.account_id = account_id
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20)) todos = db.relationship('Todo', backref='user', lazy='select') def __repr__(self): return 'Id: {}, name: {}'.format(self.id, self.name)
class TokenBlacklist(db.Model): """Blacklist representation """ id = db.Column(db.Integer, primary_key=True) jti = db.Column(db.String(36), nullable=False, unique=True) token_type = db.Column(db.String(10), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) revoked = db.Column(db.Boolean, nullable=False) expires = db.Column(db.DateTime, nullable=False) user = db.relationship('User', lazy='joined') def to_dict(self): return { 'token_id': self.id, 'jti': self.jti, 'token_type': self.token_type, 'user_identity': self.user_identity, 'revoked': self.revoked, 'expires': self.expires }
class User(db.Model): id = db.Column(db.Integer, primary_key=True) encrypted_name = db.Column(db.String(30)) encrypted_address = db.Column(db.String(30)) encrypted_email = db.Column(db.String(30)) age = db.Column(db.Integer) encrypted_likes_hobbies = db.Column(db.String(30)) encrypted_username = db.Column(db.String(20)) encrypted_password = db.Column(db.String(100)) profile_pic = db.Column(db.String(100)) display = db.Column(db.Integer) date_created = db.Column(db.DateTime, default=datetime.now) accounts = db.relationship('Accounts', backref='user', lazy=True) # getter and setter (encrypting values before saving to database) @property def name(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_name) @property def address(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_address) @property def email(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_email) @property def likes_hobbies(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_likes_hobbies) @property def username(self): return Encryption.decrypt(ENCRYPTION_KEY, self.encrypted_username) @property def password(self): return self.encrypted_password @name.setter def name(self, value): self.encrypted_name = Encryption.encrypt(ENCRYPTION_KEY, value) @address.setter def address(self, value): self.encrypted_address = Encryption.encrypt(ENCRYPTION_KEY, value) @email.setter def email(self, value): self.encrypted_email = Encryption.encrypt(ENCRYPTION_KEY, value) @likes_hobbies.setter def likes_hobbies(self, value): self.encrypted_likes_hobbies = Encryption.encrypt( ENCRYPTION_KEY, value) @username.setter def username(self, value): self.encrypted_username = Encryption.encrypt(ENCRYPTION_KEY, value) @password.setter def password(self, value): self.encrypted_password = sha256_crypt.hash(value)
class Tag(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(20))
class Stu(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(20), unique=True) grade_id = db.Column(db.Integer, db.ForeignKey("grade.id"))
class Grade(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(20), unique=True) stus = db.relationship("Stu", backref="grade", lazy=True)