class Categories(db.Model): id = db.Column(db.Integer, primary_key=True) image_file = db.Column(db.String(60), default='default.jpg') category_name = db.Column(db.String(80)) def __repr__(self): return f"Categories('{self.category_name}', '{self.id}', '{self.image_file}')"
class User(db.Model, UserMixin): __tablename__ = 'users' 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.jpeg') password = db.Column(db.String(60), nullable = False) posts = db.relationship('Post', backref='author', lazy=True) comment = db.relationship('Comment', backref='user', lazy=True) 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') @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) def __repr__(self): return f"User('{self.username}','{self.email}','{self.image_file}')"
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) password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def __repr__(self): return f"User('{self.username}', '{self.email}')"
class Quotes(db.Model): id = db.Column(db.Integer, primary_key=True) quote = db.Column(db.Text, nullable=False) category = db.Column(db.String(50), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) def __repr__(self): return f"Quotes('{self.quote}', '{self.date_posted}', '{self.category}')"
class Users(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) profile_pic = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) quote = db.relationship('Quotes', backref='author', lazy=True) def __repr__(self): return f"User('{self.username}', '{self.email}')"
class Post(db.Model): __tablename__ = 'posts' 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('users.id'), nullable = False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) quotes = db.Column(db.String(255), nullable=False) writer = db.Column(db.String(20), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.quotes}', '{self.writer}','{self.date_posted}')"
class Comment(db.Model): __tablename__ = 'comments' id = db.Column(db.Integer,primary_key = True) comment = db.Column(db.Text(), nullable = False) user_id = db.Column(db.Integer,db.ForeignKey("users.id"), nullable = False) post_id = db.Column(db.Integer,db.ForeignKey("posts.id"), nullable= False) def save_comment(self): db.session.add(self) db.session.commit() def delete_comment(self): db.session.delete(self) db.session.commit() @classmethod def get_comments(cls,post_id): comments = Comment.query.filter_by(post_id=post_id).all() return comments def __repr__(self): return f'Comment:{self.comment}'
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(60)) username = db.Column(db.String(60), unique=True) email = db.Column(db.String(60), unique=True) image_file = db.Column(db.String(60), default='default.jpg') password = db.Column(db.String(60)) def __init__(self, name, username, email, password): self.name = name self.username = username self.email = email self.password = bcrypt.generate_password_hash(password) def __repr__(self): return f"User('{self.name}', '{self.username}', '{self.email}', ('{self.password}', '{self.image_file}'))"
class Quotes(db.Model): id = db.Column(db.Integer, primary_key=True) quote = db.Column(db.String(100)) quote_by = db.Column(db.String(100), default='') language = db.Column(db.String(100), default='en') color_code = db.Column(db.String(100), default='#ffffff') font_family = db.Column(db.String(100), default='default') is_active = db.Column(db.Boolean(), default=True) created_at = db.Column(db.DateTime(), default=datetime.utcnow()) updated_at = db.Column(db.DateTime(), default=datetime.utcnow()) image_file = db.Column(db.String(60), default='default.jpg') category_id = db.Column(db.String(100), db.ForeignKey('categories.category_name')) def __repr__(self): return f"Quotes('{self.quote}', '{self.category_id}', '{self.image_file}')"