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


Python Category.get_or_insert方法代码示例

本文整理汇总了Python中models.Category.get_or_insert方法的典型用法代码示例。如果您正苦于以下问题:Python Category.get_or_insert方法的具体用法?Python Category.get_or_insert怎么用?Python Category.get_or_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Category的用法示例。


在下文中一共展示了Category.get_or_insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_or_insert [as 别名]
def create(request):
    if not admin():
        return HttpResponseRedirect(users.create_login_url('/blogs'))
    form = BlogForm(request.POST)
    form.fields['category'].choices = [('', '请选择')] + [(category.key(), category.name) for category in Category.all()]
    if form.is_valid():
        blog = Blog()
        blog.title = form.cleaned_data['title']
        blog.content = form.cleaned_data['content']
        if form.cleaned_data['category']:
            blog.category = Category.get(form.cleaned_data['category'])
        elif form.cleaned_data['user_tag']:
            blog.category = Category.get_or_insert(form.cleaned_data['user_tag'], name=form.cleaned_data['user_tag'])
        blog.create()
        return HttpResponseRedirect('/blogs')
    else:
        return new(request)
开发者ID:qubic,项目名称:myblogongae,代码行数:19,代码来源:views.py

示例2: create

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_or_insert [as 别名]
def create(request):
    if not admin():
        return HttpResponseRedirect(users.create_login_url("/blogs"))
    form = BlogForm(request.POST)
    form.fields["category"].choices = [("", "请选择")] + [(category.key(), category.name) for category in Category.all()]
    if form.is_valid():
        blog = Blog()
        blog.title = form.cleaned_data["title"]
        blog.content = form.cleaned_data["content"]
        if form.cleaned_data["category"]:
            blog.category = Category.get(form.cleaned_data["category"])
        elif form.cleaned_data["user_tag"]:
            blog.category = Category.get_or_insert(form.cleaned_data["user_tag"], name=form.cleaned_data["user_tag"])
        blog.create()
        return HttpResponseRedirect("/blogs")
    else:
        return new(request)
开发者ID:proming,项目名称:myblogongae,代码行数:19,代码来源:views.py

示例3: update

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_or_insert [as 别名]
def update(request, key):
    if not admin():
        return HttpResponseRedirect(users.create_login_url('/blogs'))
    form = BlogForm(request.POST)
    form.fields['category'].choices = [('', '请选择')] + [(category.key(), category.name) for category in Category.all()]
    if form.is_valid():
        blog = Blog.get(key)
        blog_category_db=blog.category
        blog.title = form.cleaned_data['title']
        blog.content = form.cleaned_data['content']
        if form.cleaned_data['category']:
            blog.category = Category.get(form.cleaned_data['category'])
        elif form.cleaned_data['user_tag']:
            blog.category = Category.get_or_insert(form.cleaned_data['user_tag'], name=form.cleaned_data['user_tag'])
        else:
            blog.category = None
        blog.put()
        if blog_category_db and blog_category_db.blog_set.count() == 0:
            blog_category_db.delete()
        return HttpResponseRedirect('/blogs')
    else:
        return edit(request, key)
开发者ID:qubic,项目名称:myblogongae,代码行数:24,代码来源:views.py


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