本文整理汇总了Python中models.Post.author_id方法的典型用法代码示例。如果您正苦于以下问题:Python Post.author_id方法的具体用法?Python Post.author_id怎么用?Python Post.author_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.author_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author_id [as 别名]
def add_post():
form = NewPostForm()
if form.validate_on_submit():
post = Post()
form.populate_obj(post)
post.author_id = current_user.id
db.session.add(post)
db.session.commit()
return redirect('/')
return render_template("add_post.html", form = form)
示例2: add_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author_id [as 别名]
def add_post():
form = PostForm(request.form)
if request.method == 'POST' and form.validate():
post = Post()
form.populate_obj(post)
post.author_id = g.user.id
post.timestamp = datetime.utcnow()
db.session.add(post)
db.session.commit()
return redirect(url_for('show_post', post_id=post.id))
return render_template('content_add_post.html',
title='Add post',
form=form,
user=g.user)
示例3: create_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author_id [as 别名]
def create_post():
if request.method == 'GET':
if 'username' not in session:
return redirect('/login')
return render_template('newpost.html')
else:
title = request.form['title']
text = request.form['text']
post = Post(title, text)
user = current_user()
post.author_id = user.id
db.session.add(post)
db.session.commit()
return redirect('/post/' + str(post.id))
示例4: save
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author_id [as 别名]
def save(cls, request: Request, *args, **kwargs):
""" Метод для сохранения поста
:param request:
:param kwargs:
:return:
"""
if request.get("id", False):
post = blog.get_post(request.get("id"))
else:
post = Post()
post.title = request.get("title")
post.short = request.get("short")
post.imgs = request.get("imgs", [])
post.body = request.get("body", "")
post.tags = request.get("tags", [])
post.category = request.get("category", None)
post.draft = request.get("draft", True)
post.author_id = request.get("author_id", False)
post.author_name = request.get("author_name", False)
post.source = request.get("source", False)
return {"post_id": post.save()}