當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。