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 Form(db.Model): id = db.Column(db.Integer, primary_key=True) names = db.Column(db.String(150), nullable=False, unique=True) number = db.Column(db.String(20), nullable=False, unique=True) def __init__(self, names): self.names = names self.number = number def __repr__(self): return f'{self.names} : {self.number}'
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) phone = db.Column(db.String(15)) date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __init__(self, phone, user_id): self.phone = phone self.user_id = user_id def __repr__(self): return f'The title of the post is {self.title} \n and the content is {self.content}'
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(200)) content = db.Column(db.String(300)) date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __inti__(self, title, content, user_id): self.title = title self.content = content self.user_id = user_id def __repr__(self): return f"The title of the post is {self.title}\n and the content is {self.content}."
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}'
class Number(db.Model): id = db.Column(db.Integer, primary_key = True) number = db.Column(db.String(20), nullable = False, unique = True) update = db.Column(db.String(300)) date_created = db.Column(db.DateTime, nullable = False, default = datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable = False) def __init__(self,update,user_id, number): self.update = update self.user_id = user_id self.number = number def __repr__(self): return f'The number is {self.number}.'
class Phone(db.Model): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(200)) last_name = db.Column(db.String(300)) area_code = db.Column(db.Integer) number = db.Column(db.String(300)) date_create = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __init__(self, first_name, last_name, area_code, number, user_id): self.first_name = first_name self.last_name = last_name self.area_code = area_code self.number = number self.user_id = user_id def __repr__(self): return f'Thank you, {self.first_name} for signing up!.'