Ejemplo n.º 1
0
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)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def validate_password(self, password):
        return check_password_hash(self.password_hash, password)
Ejemplo n.º 2
0
class AdminUser(db.Model,UserMixin):
    __tablename__='admins'
    id=db.Column(db.Integer,primary_key=True)
    username=db.Column(db.String(40),nullable=False,index=True)
    password_hash=db.Column(db.String(128))
    blog_title=db.Column(db.String(60))
    blog_sub_title=db.Column(db.String(120))
    name=db.Column(db.String(60))
    about=db.Column(db.Text)

    @property.setter
    def set_password(self,password):
        self.password_hash=generate_password_hash(password)

    def verify_password(self,password):
        return check_password_hash(self.password_hash,password)
Ejemplo n.º 3
0
class Comment(db.Model):
    id=db.Column(db.Integer,primary_key=True)
    author=db.Column(db.String(40))
    email=db.Column(db.String(256))
    site=db.Column(db.String(255))
    timestamp=db.Column(db.DateTime,default=datetime.utcnow,index=True)
    body=db.Column(db.Text)
    from_admin=db.Column(db.Boolean,default=False) #是否是管理员评论
    reviewed=db.Column(db.Boolean,default=False)  #是否通过审核,为了防止垃圾评论或者是不当的评论

    post_id=db.Column(db.Integer,db.ForeignKey('Post.id'))
    post=db.relationship('Post',back_populates='comments')

    replied_id=db.Column(db.Integer,db.ForeignKey('Comment.id'))
    replied=db.relationship('Comment',back_populates='replies',remote_site=[id])  #子评论
    replies=db.relationship('Comment',back_populates='replied',cascade='all,delete-orphan')  #父评论,对应多个子评论
Ejemplo n.º 4
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)
    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')
    can_comment = db.Column(db.Boolean, default=True)
Ejemplo n.º 5
0
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)
    from_admin = db.Column(db.Boolean, default=False)
    reviewed = db.Column(db.Boolean, default=False)
    timestamp = db.Column(db.DateTime, default=datetime.utcnow, index=True)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    post = db.relationship('Post', back_populates='comments')

    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')
Ejemplo n.º 6
0
class Post(db.Model):
    id=db.Column(db.Integer,primary_key=True)
    blog_title=db.Column(db.String(60))
    body=db.Column(db.Text)
    timestamp=db.Column(db.DateTime,default=datetime.utcnow)

    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.º 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
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 8
0
class Link(db.Model):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(40))
    url=db.Column(db.String(255))
Ejemplo n.º 9
0
class Category(db.Model):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(60))

    #与模型Post建立一对多关系
    posts=db.relationship('Post',back_populates='category')
Ejemplo n.º 10
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True)
    post = db.relationship('Post', back_populates='category')