本文整理汇总了Python中blog.models.Article.update方法的典型用法代码示例。如果您正苦于以下问题:Python Article.update方法的具体用法?Python Article.update怎么用?Python Article.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Article
的用法示例。
在下文中一共展示了Article.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ajax_editor
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import update [as 别名]
def ajax_editor(request):
# 保存文章
# 获取作者
user = request.user
if not user:
msg = "error|无法获取作者"
else:
# 获取前段数据
try:
html = request.POST.get("html","")
title = request.POST.get("title","")
tag = request.POST.get("tag","")
keys = request.POST.get("keys","")
id = request.POST.get("id","")
except Exception as e:
print(e)
msg = u"error|前端数据获取失败"
print msg
else:
# 前端没有id传过来则新建
# 有id传过来则更新
if not id:
# script过滤
html = re_js(html)
title = re_js(title)
tag = re_js(tag)
keys = re_js(keys)
try:
article = Article(title=title,
user = user,
article_class=tag,
keyword=keys,
content = html)
article.save()
except Exception as e:
print(e)
msg = "error|文章保存失败"
else:
msg = "ok|保存成功"
else:
try:
article = Article.objects.filter(id=id)
# 权限检查 操作和数据库中记录的用户不是一个人则抛出异常,无权修改.超级管理员有权修改
if article[0].user == user or user.is_superuser:
article.update(title=title,
user = user,
article_class=tag,
keyword=keys,
content = html)
else:
msg ="error|你没有修改权限"
print(msg)
raise Exception(msg)
except Exception as e:
print(e)
msg = "error|更新失败"
else:
msg = "ok|更新成功"
return HttpResponse(msg)