Ejemplo n.º 1
0
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)
    can_comment = db.Column(db.Boolean, default=True)
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
    category = db.relationship('Category', back_populates='posts')
    comments = db.relationship('Comment', back_populates='post',
                               cascade='all, delete-orphan')
Ejemplo n.º 2
0
class Post(Base):
    """
    博客文章数据表模型类
    """
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(60))
    content = db.Column(db.Text)
    create_time = db.Column(db.DateTime, default=datetime.utcnow)
    categories = db.relationship('Category', secondary='post_category_middle')
    comments = db.relationship('Comment', cascade='all, delete-orphan')
    can_comment = db.Column(db.Boolean, default=True)
    # SEO 相关,写在 <meta> 标签内
    description = db.Column(db.String(150))
Ejemplo n.º 3
0
class Post(Base):
    """
    博客文章数据表模型类
    """
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(60))
    content_markdown = db.Column(
        db.Text)  # 储存 markdown 格式的正文,用以编辑时传递给 markdown 编辑器
    content = db.Column(db.Text)  # 储存 HTML 格式正文,用来展示
    create_time = db.Column(db.DateTime, default=datetime.utcnow)
    categories = db.relationship('Category', secondary='post_category_middle')
    comments = db.relationship('Comment', cascade='all, delete-orphan')
    can_comment = db.Column(db.Boolean, default=True)
    description = db.Column(db.String(150))  # SEO 相关,写在 <meta> 标签内
    trash = db.Column(db.Boolean, default=False)
    published = db.Column(db.Boolean, default=True)
Ejemplo n.º 4
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author = db.Column(db.String(30))
    email = db.Column(db.String(64))
    site = db.Column(db.String(255))
    body = db.Column(db.Text)
    from_admin = db.Column(db.Boolean, default=False)
    reviewed = db.Column(db.Boolean, default=False)
    timestamp = db.Column(db.DateTime, default=datetime.utcnow)
    replied_id = db.Column(db.Integer, db.ForeignKey('comment.id'))
    replied = db.relationship('Comment', back_populates='replies',
                              remote_side=[id])
    replies = db.relationship('Comment', back_populates='replied',
                              cascade='all')
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    post = db.relationship('Post', back_populates='comments')
Ejemplo n.º 5
0
class Comment(Base):
    """
    文章评论数据表模型类
    """
    id = db.Column(db.Integer, primary_key=True)
    author = db.Column(db.String(16))
    email = db.Column(db.String(64))
    site = db.Column(db.String(256))
    content = db.Column(db.Text)
    create_time = db.Column(db.DateTime, default=datetime.utcnow)
    from_admin = db.Column(db.Boolean, default=False)
    reviewed = db.Column(db.Boolean, default=False)
    replied_id = db.Column(db.Integer, db.ForeignKey('comment.id'))
    replied = db.relationship('Comment', remote_side=[id], uselist=False)
    replies = db.relationship('Comment', cascade='all')
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    post = db.relationship('Post', uselist=False)
Ejemplo n.º 6
0
class Category(Base):
    """
    文章分类数据表模型
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(12), nullable=False, unique=True)
    posts = db.relationship("Post", secondary='post_category_middle')
    show = db.Column(db.Boolean, default=True)
Ejemplo n.º 7
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True)
    posts = db.relationship('Post', back_populates='category')

    def delete(self):
        default_category = Category.query.get(1)
        posts = self.posts[:]
        for post in posts:
            post.category = default_category
        with db.auto_commit():
            db.session.delete(self)
Ejemplo n.º 8
0
class Category(Base):
    """
    文章分类数据表模型
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(12), nullable=False, unique=True)
    posts = db.relationship("Post", secondary='post_category_middle')
    alias = db.Column(db.String(24), unique=True, nullable=True)
    show = db.Column(db.Boolean, default=True)

    def delete(self):
        """
            执行删除分类操作
        """
        if self.posts:
            for post in self.posts:
                # 如果要删除的分类文章没有其它分类则将其移动至默认分类下
                if len(post.categories) == 1:
                    with db.auto_commit():
                        post.categories = [Category.query.get(1)]
                        db.session.add(post)

        with db.auto_commit():
            db.session.delete(self)