当前位置: 首页>>代码示例>>Python>>正文


Python Blog.exists方法代码示例

本文整理汇总了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/')
开发者ID:kiStephane,项目名称:MyBlog_Assignment,代码行数:14,代码来源:views.py

示例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)
    )
开发者ID:kiStephane,项目名称:MyBlog_Assignment,代码行数:14,代码来源:views.py

示例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)
    )
开发者ID:kiStephane,项目名称:MyBlog_Assignment,代码行数:40,代码来源:views.py


注:本文中的models.Blog.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。