class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.png') # profile picture password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) # makes reference of user connected to post # 30 minutes to allow for password reset def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') # verify the reset @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) # how object is printed def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(30), unique=True, nullable=False) description = db.Column(db.String(300)) def __repr__(self): return self.name
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default="default.png") password = db.Column(db.String(60), nullable=False) post = db.relationship('Post', backref='author', lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}, '{self.image_file}')"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) intro = db.Column(db.String(200)) body = db.Column(db.Text(), nullable=False) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) user_name = db.Column(db.Integer, db.ForeignKey('user.username')) user = db.relationship("User", back_populates="posts") @property def slugified_title(self): return slugify(self.title) def __repr__(self): return 'Post {}'.format(self.title)
class Movie(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(200), nullable=False) year = db.Column(db.Integer, nullable=False) rating = db.Column(db.Float, nullable=False) def __repr__(self): return f"Movie ('{self.title}', '{self.year}', '{self.rating}')"
class ContactThankYou(db.Model): id = db.Column(db.Integer, primary_key=True) intro = db.Column(db.String()) body = db.Column(db.Text()) edited = db.Column(db.DateTime, index=True, default=datetime.utcnow) def __repr__(self): return self.intro
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) # user id that authors the post # how object is printed def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), unique=True) email = db.Column(db.String(120), unique=True) password = db.Column(db.String(128)) about_me = db.Column(db.String(10000)) created = db.Column(db.DateTime, default=datetime.utcnow()) firstname = db.Column(db.String(50)) lastname = db.Column(db.String(50)) password_code = db.Column(db.String(50)) posts = db.relationship("Post", back_populates="user") role = db.relationship('Role', secondary=users_roles, backref=db.backref('users', lazy='dynamic')) def __str__(self): return self.username
class About(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String()) title_description = db.Column(db.Text()) red_intro = db.Column(db.String()) black_intro = db.Column(db.String()) intro_description = db.Column(db.Text()) first_offer = db.Column(db.String()) first_offer_description = db.Column(db.Text()) second_offer = db.Column(db.String()) second_offer_description = db.Column(db.Text()) third_offer = db.Column(db.String()) third_offer_description = db.Column(db.Text()) first_step = db.Column(db.String()) first_step_description = db.Column(db.Text()) second_step = db.Column(db.String()) second_step_description = db.Column(db.Text()) third_step = db.Column(db.String()) third_step_description = db.Column(db.Text()) edited = db.Column(db.DateTime, index=True, default=datetime.utcnow) def __repr__(self): return self.title
class Home(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String()) title_description = db.Column(db.Text()) about_intro = db.Column(db.String()) about_description = db.Column(db.Text()) first_card_title = db.Column(db.String()) first_card_description = db.Column(db.Text()) second_card_title = db.Column(db.String()) second_card_description = db.Column(db.Text()) third_card_title = db.Column(db.String()) third_card_description = db.Column(db.Text()) blog_intro = db.Column(db.String()) blog_title = db.Column(db.Text()) edited = db.Column(db.DateTime, index=True, default=datetime.utcnow) def __repr__(self): return self.title
class UniversalPage(db.Model): name = db.Column(db.String(64), nullable=False) url = db.Column(db.Unicode(20), unique=True, nullable=False) id = db.Column(db.Integer, primary_key=True)