當前位置: 首頁>>代碼示例>>Python>>正文


Python Tag.tag_name方法代碼示例

本文整理匯總了Python中blog.models.Tag.tag_name方法的典型用法代碼示例。如果您正苦於以下問題:Python Tag.tag_name方法的具體用法?Python Tag.tag_name怎麽用?Python Tag.tag_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在blog.models.Tag的用法示例。


在下文中一共展示了Tag.tag_name方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: addtag

# 需要導入模塊: from blog.models import Tag [as 別名]
# 或者: from blog.models.Tag import tag_name [as 別名]
def addtag(request):
	tag_name=request.GET.get('tag_name')
	newtag=Tag()
	newtag.tag_name=tag_name
	newtag.save()
	id=newtag.id
	tag={'id':id,'tag_name':tag_name}
	tag=json.dumps(tag)
	return HttpResponse(tag)
開發者ID:strong-ge,項目名稱:firstBlog,代碼行數:11,代碼來源:views.py

示例2: save_new_review_article

# 需要導入模塊: from blog.models import Tag [as 別名]
# 或者: from blog.models.Tag import tag_name [as 別名]
def save_new_review_article(request):
    if request.method == 'POST' and request.user.is_authenticated():
        form = AddArticleForm(request.POST)
        work_id = request.POST.get('work_id')
        work = Work.objects.get(pk=work_id)
        artist = work.creator
        if form.is_valid():
            article = form.save()
            author = Author.objects.filter(user=request.user)[0]
            article.author = author
            article.work_link = work
            article.artist_link = artist
            article.save()
            tags_string = request.POST.get('tags')
            tags_list = tags_string.split(',')
            tags = []

            for tag in tags_list:
                tags.append(tag.strip().lower().replace('-', ' ').replace('_', ' '))

            # A Tag is another model, linked to the "article" via a ManyToMany field
            # Here we check to see if the user has entered tags that already exist in the database
            for tag in tags:
                pre_existing_tags = Tag.objects.filter(tag_name=tag)
                if len(pre_existing_tags) > 0:
                    pre_existing_tag = pre_existing_tags[0]
                    article.tags.add(pre_existing_tag)
                    article.save()
                else:
                    #create a new tag, save it to the DB, and add it to the article
                    new_tag = Tag()
                    new_tag.tag_name = tag
                    new_tag.save()
                    article.tags.add(new_tag)
                    article.save()
            return HttpResponseRedirect('/wc_admin/view_article/?id=' + str(article.id))
        else:
            error_message = 'The form was not valid. The data was not saved.'
            return render(request, 'blog/error.html', {'error_message': error_message, 'form': form})
    else:
        error_message = 'The info was not properly posted. The data was not saved.'
        return render(request, 'blog/error.html', {'error_message': error_message})
開發者ID:PattMayne,項目名稱:weird_canada,代碼行數:44,代碼來源:views.py


注:本文中的blog.models.Tag.tag_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。