本文整理汇总了Python中blog.models.Article.find_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Article.find_by_id方法的具体用法?Python Article.find_by_id怎么用?Python Article.find_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Article
的用法示例。
在下文中一共展示了Article.find_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: article_edit
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import find_by_id [as 别名]
def article_edit(id):
form = ArticleEditForm()
form.category_id.choices = Category.choices()
article = Article.find_by_id(int(id))
form.title.data = article.title
form.body.data = article.body
form.tag.data = article.tag
form.category_id.data = article.category_id
form.is_open.data = article.is_open
form.id.data = id
return render_template('article_edit.html',
title=u'编辑' + article.title,
form=form)
示例2: article_commit
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import find_by_id [as 别名]
def article_commit():
if g.user.is_admin():
data = request.form
title, category, tag, is_open, body, text, art_id = data['title'], data['category'], data['tag'], \
data['open'], data['body'], data['text'], data["id"]
if title == '' or tag == '' or body == '' or text == '':
return json.dumps({'msg': u'必填字段不能为空'})
if art_id:
article = Article.find_by_id(int(id))
article.title = title
article.category_id = category
article.tag = tag
article.is_open = is_open
article.body = body
article.text = text
article.timestamp = datetime.datetime.now()
db.session.add(article)
else:
nowtime = datetime.datetime.now()
article = Article(title=title,
body=body,
user_id=g.user.id,
category_id=category,
text=text,
timestamp=nowtime,
tag=tag,
is_open=is_open)
article.post_date = nowtime
try:
db.session.add(article)
db.session.commit()
return json.dumps({'msg': u'保存成功'})
except:
return json.dumps({'msg': u'保存失败'})
else:
return json.dumps({'msg': u'请用管理员账号登陆'})