本文整理汇总了Python中models.Blog.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.exists方法的具体用法?Python Blog.exists怎么用?Python Blog.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Blog
的用法示例。
在下文中一共展示了Blog.exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import exists [as 别名]
def delete_blog(request, blog_id):
init_session_data(request)
if Blog.exists(blog_id):
blog = Blog.objects.get(id=int(blog_id))
request.session['blog_modified'] = str(blog.id)
blog.delete()
request.session['modification'] = "delete"
request.session['articles_deleted'] = request.session['articles_deleted'] | {blog_id}
else:
request.session['modification'] = None
return HttpResponseRedirect('/myblog/')
示例2: display_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import exists [as 别名]
def display_blog(request, blog_id):
init_session_data(request)
if Blog.exists(blog_id):
blog = Blog.objects.get(id=int(blog_id))
request.session['articles_visited'].append(blog_id)
else:
blog = None
return render_to_response("displayblog.html",
{'blog': blog},
context_instance=RequestContext(request)
)
示例3: edit_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import exists [as 别名]
def edit_blog(request, blog_id):
init_session_data(request)
if Blog.exists(blog_id):
blog = Blog.objects.get(id=int(blog_id))
else:
return add_blog(request, int(blog_id))
request.session['blog_modified'] = blog.id
if request.method == "POST" and request.POST.has_key("content") and request.POST.has_key("title"):
if request.session.get('edited_version'):
edited_version = int(request.session.get('edited_version'))
else:
edited_version = -1
content = html_to_content(request.POST["content"])
if edited_version == blog.version:
blog.content_body = content
blog.title = request.POST["title"]
blog.version += 1
blog.save()
if request.session['modification'] != 'add':
request.session['modification'] = 'edit'
request.session['articles_edited'] = request.session['articles_edited'].append(blog_id)
return HttpResponseRedirect('/myblog/')
else:
request.session['edited_version'] = str(blog.version)
return render_to_response("conflict.html",
{'blog': blog, 'user_content': content},
context_instance=RequestContext(request)
)
request.session['edited_version'] = str(blog.version)
return render_to_response("edit.html",
{'blog': blog},
context_instance=RequestContext(request)
)