本文整理汇总了Python中models.Tags.save方法的典型用法代码示例。如果您正苦于以下问题:Python Tags.save方法的具体用法?Python Tags.save怎么用?Python Tags.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tags
的用法示例。
在下文中一共展示了Tags.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import save [as 别名]
def post(request, slug):
try:
db_blog = Posts.objects.get(slug=slug)
except:
db_blog = None
if db_blog:
db_blog.tag_set.all().delete()
form = PostsForm(request.POST, instance=db_blog)
##print( "content %s" % request.POST.get("content"))
if form.is_valid():
blog_post = form.save(commit=False)
blog_post.mark_down = blogContentRender(blog_post.content)
tags = blog_post.tags.split(',')
blog_post.save()
for tag in tags:
t = Tags()
t.post = Posts.objects.get(slug=blog_post.slug)
t.name = tag.strip()
t.save()
form.save_m2m()
return HttpResponseRedirect("/")
c = {"form": form, "slug": slug}
c.update(csrf(request))
t = get_template("publish.html")
return HttpResponse(t.render(Context(c)))
示例2: insert
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import save [as 别名]
def insert(request):
status=None
if request.method == 'POST':
# save new post
Usr_Name = request.POST.get('name','')
Usr_Mobile = request.POST.get('mobile','')
Usr_Remark = request.POST.get('remark','')
tags = request.POST.get('tags','')
pre_id = request.POST.get('pre_id','')
p_uuid = uuid.uuid1()
p = People(Usr_Name = Usr_Name,Usr_Mobile = Usr_Mobile,Usr_Remark=Usr_Remark,active = 0,isdel = 0,uuid = p_uuid,)
p.save()
for tag in tags.replace(u',',',').split(','):
try:
t = Tags.objects.get(tag = tag)
except Tags.DoesNotExist:
newtag = Tags(tag=tag)
newtag.save()
p.tags.add(newtag)
p.save()
else:
p.tags.add(t)
p.save()
if request.user.is_superuser:
status="ok"
p.Cluster_id = 0
p.save()
return render_to_response('usernet/index.html', {'status':status,},
context_instance=RequestContext(request))
if pre_id =='':
pre_id = request.user
if pre_id != '':
try:
pre = People.objects.filter(Usr_Mobile = pre_id,active = 1)
except People.DoesNotExist:
print "error"
else:
p.Prev_Usr=pre[0]
p.Cluster_id = pre[0].Cluster_id
p.save()
status="ok"
# Get all posts from DB
return render_to_response('usernet/index.html', {'status':status,},
context_instance=RequestContext(request))
示例3: update
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import save [as 别名]
def update(request):
if request.method == 'GET':
pid = request.GET.get('id')
p = People.objects.get(id = pid)
tags = p.tags.all()
tag=[]
ta = ''
for i in tags:
tag.append(i.tag)
ta = ta+ i.tag+','
return render_to_response('usernet/update.html',{'person':p ,'tags':tag,'ta':ta,},
context_instance=RequestContext(request))
if request.method == 'POST':
pid = request.POST.get('id')
Usr_Name = request.POST.get('name','')
Usr_Mobile = request.POST.get('mobile','')
Usr_Remark = request.POST.get('remark','')
tags = request.POST.get('tags','')
pre_id = request.POST.get('pre_id','')
p = People.objects.get(id = pid)
p.Usr_Name =Usr_Name
p.Usr_Mobile = Usr_Mobile
p.Usr_Remark = Usr_Remark
for tag in tags.replace(u',',',').split(','):
try:
t = Tags.objects.get(tag = tag)
except Tags.DoesNotExist:
newtag = Tags(tag=tag)
newtag.save()
p.tags.add(newtag)
p.save()
else:
p.tags.add(t)
p.save()
status = "Update " + p.Usr_Name + " successfully!"
status_code = 1
return render_to_response('usernet/message.html',{'status':status,'status_code':status_code,},
context_instance=RequestContext(request))
示例4: add_article
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import save [as 别名]
def add_article(request):
"""提交文章"""
if request.META.has_key('HTTP_X_FORWARDED_FOR'):
vsip = request.META['HTTP_X_FORWARDED_FOR']
else:
vsip = request.META['REMOTE_ADDR']
blog_title = request.POST.get("blog_title","")#根据标题判断是访问还是新增
if blog_title:
blog_content = request.POST.get("blog_content","")
blog_quote = eval(request.POST.get("blog_quote",""))
blog_class = request.POST.get("blog_class","")
blog_tags = eval(request.POST.get("blog_tags",""))
# print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^66"
# print blog_title
# print blog_content
# print blog_quote
# print blog_class
# print blog_tags,"|",type(blog_tags)
# print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
if not blog_content or not blog_quote or not blog_class or not blog_title:
return HttpResponse(json.dumps({"status":"1","messages":"parameter error"}), content_type="application/json")
if blog_quote["sign"] == "C":
cornerite = "C"
else:
cornerite = ""
# print "***********************************"
# print blog_title
# print blog_content
# print blog_quote
# print blog_class
# print blog_tags
# print "***********************************"
author = Author.objects.get(author_name="guowei1003")
NewArticle = Article(
title=blog_title,
author=author,
location="北京",
quote=blog_quote["quote_url"],
article_class=blog_class,
article_lead=blog_content,
article_reads='0',
article_likes='0',
article_collects='0',
cornerite=cornerite
)
NewArticle.save()
for tag in blog_tags:
try:
mtag = Tags.objects.get(tag=tag)
except:
mtag = Tags(tag=tag)
mtag.save()
NewArticle.article_tags.add(mtag)
return HttpResponse(json.dumps({"status":"0"}), content_type="application/json")
else:
ClassList = {}
AllTags = Tags.objects.all()[:50]
AllClass = Article.objects.values("article_class")
for c in AllClass:
if c["article_class"] in ClassList:
ClassList[c["article_class"]] +=1
else:
ClassList[c["article_class"]] = 1
title = "撰写博文"
return render_to_response("blog/blog_addarticle.html",locals())