本文整理汇总了Python中blog.models.Article.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get_by_id方法的具体用法?Python Article.get_by_id怎么用?Python Article.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Article
的用法示例。
在下文中一共展示了Article.get_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import get_by_id [as 别名]
def update_article(request, id):
"""Enables Article update"""
article = Article.get_by_id(int(id))
if article:
if request.method == 'POST':
form = ArticleForm(request.POST)
if form.is_valid():
article.title = form.cleaned_data['title']
article.content = form.cleaned_data['content']
article.put()
messages.add_message(request,
messages.INFO,
u'Article %s created'
% form.cleaned_data['title'])
time.sleep(1)
return redirect('home')
else:
form = ArticleForm({'title': article.title,
'content': article.content})
return render(request, 'article/create.html', locals())
else:
messages.add_message(request,
messages.ERROR,
u'Article not found')
return redirect('home')
示例2: delete_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import get_by_id [as 别名]
def delete_article(request, id):
"""Enables Article deletion"""
article = Article.get_by_id(int(id))
if article:
messages.add_message(request,
messages.INFO,
u'Article %s deleted' % article.title)
article.delete()
time.sleep(1)
else:
messages.add_message(request, messages.ERROR, u'Article not found')
return redirect('home')