class Category(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True) posts = db.relationship('Post', backref='category') def delete(self): default_category = Category.query.get(1) posts = self.posts[:] for post in posts: post.category = default_category db.session.delete(self) db.session.commit()
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) author = db.Column(db.String(30)) email = db.Column(db.String(254)) site = db.Column(db.String(255)) body = db.Column(db.Text) form_admin = db.Column(db.Boolean, default=False) reviewed = db.Column(db.Boolean, default=False) timestamp = db.Column(db.DateTime, default=datetime.utcnow, index=True) replied_id = db.Column(db.Integer, db.ForeignKey('comment.id')) post_id = db.Column(db.Integer, db.ForeignKey('post.id')) replies = db.relationship('Comment', backref=db.backref('replied', remote_side=[id]), cascade='all, delete-orphan')
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60)) body = db.Column(db.Text) timestamp = db.Column(db.DateTime, default=datetime.utcnow, index=True) can_comment = db.Column(db.Boolean, default=True) category_id = db.Column(db.Integer, db.ForeignKey('category.id')) comments = db.relationship('Comment', backref='post', cascade='all, delete-orphan')
class Admin(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20)) password_hash = db.Column(db.String(128)) blog_title = db.Column(db.String(60)) blog_sub_title = db.Column(db.String(100)) name = db.Column(db.String(30)) about = db.Column(db.Text) @property def password(self): raise AttributeError('password is not a readable attribute') @password.setter def password(self, password): self.password_hash = generate_password_hash(password) def validate_password(self, password): return check_password_hash(self.password_hash, password)
class Link(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30)) url = db.Column(db.String(255))