class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) # each of our usernames have to be unique and it cant be empty: username = db.Column(db.String(150), nullable=False, unique=True) phone = db.Column(db.String(15), nullable=False, unique=True) email = db.Column(db.String(150), nullable=False, unique=True) password = db.Column(db.String(256), nullable=False) # 'lazy' this is only loaded when "we need it" or reqquested post = db.relationship('Post', backref='author', lazy=True) def __init__(self, username, phone, email, password): self.username = username self.phone = phone self.email = email # this will start our encryption method: self.password = self.set_password(password) def set_password(self, password): """ Grab the password that is passed into the method return the hashed verion of the passowrd which will be stored inside the database """ self.pw_hash = generate_password_hash(password) return self.pw_hash # The following is needed to see when things go into our database, or object gets created so we can than use it: def __repr__(self): return f'{self.username} has been created with the following email: {self.email}'
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(150), nullable=False, unique=True) email = db.Column(db.String(150), nullable=False, unique=True) password = db.Column(db.String(256), nullable=False) post = db.relationship('Phone', backref='author', lazy=True) def __init__(self, username, email, password): self.username = username self.email = email self.password = self.set_password(password) def set_password(self, password): self.pw_hash = generate_password_hash(password) return self.pw_hash def __repr__(self): return f'{self.username} has been created with {self.email}'