def update_post(content): # get方法先获取一条 post_one = Post.get(post_pk=1) post_one.content = content
def edit_post_form(post_id): """Displays the form to edit the specified post""" post = Post.get(post_id) tags = Tag.get_all() return render_template('post_edit_form.html', post=post, tags=tags)
# 修改数据 @db_session def update_post(content): # get方法先获取一条 post_one = Post.get(post_pk=1) post_one.content = content content = "内容暂无" update_post(content) # 表关联操作 with db_session: p = Post.get(post_pk=1) Comment(content="你瞅啥", post=p) Comment(content="瞅你咋地", post=p) # 查看关联的数据 print(p.comments) # 之后就可以通过p.comments取到与之关联的评论。 # 那么再来试试多对多关系 with db_session: c1 = Category(name="tech") c2 = Category(name="blog") Post(title="第5篇文章", content="Hello world too", categories=[c1]) Post(title="第6篇文章", content="Hello world 3", categories=[c1, c2])
def show_post(post_id): """Displays info about the specified post""" post = Post.get(post_id) return render_template('post_details.html', post=post)