本文整理汇总了Python中models.BlogPost.title方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.title方法的具体用法?Python BlogPost.title怎么用?Python BlogPost.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.BlogPost
的用法示例。
在下文中一共展示了BlogPost.title方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submitApost
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import title [as 别名]
def submitApost(self):
returnedTags=[]
def Tagupdate (tag):
#logging.info(self.tags.filter('tag',tag).count())
if tag!="" and self.tags.filter('tag',tag).count()==0:#tag does not exist
return(Tag(tag=tag).put())
else:
return(self.tags.filter('tag',tag)[0].key())#otherwise find its key
posttagkeys=[]
if not self.tags:#Tags are empty therefore insert new tags
posttagkeys=[Tag(tag=tag).put() for tag in self.posttags if tag!=""]
elif self.posttags[0]!="": posttagkeys=map(Tagupdate ,self.posttags)
for key in posttagkeys:
obj=db.get(key)
returnedTags.append({"tag":obj.tag,"tagid":obj.key().id()})
catnames=[]
catkeys=[]
if self.categories: #categories exist make list of them
[catnames.append(catobj.category) for catobj in self.categories]
[catkeys.append(catobj.key()) for catobj in self.categories]
catobjs=dict(zip(catnames,catkeys))
if self.postcategory in catobjs.keys():catkey=catobjs[self.postcategory]
else:#this post has a new category
newcatobj=Category()
newcatobj.category=self.postcategory
newcatobj.put()
catkey=newcatobj.key()
else:
newcatobj=Category()
newcatobj.category=self.postcategory
newcatobj.put()
catkey=newcatobj.key()
post=BlogPost()
post.title=self.title
post.body=self.body
post.tags=posttagkeys
post.category=catkey
post.put()
self.deleteMemcache(self)
self.refetch(self)
return(post.key(),returnedTags)
示例2: add_post
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import title [as 别名]
def add_post(request):
context = RequestContext(request)
if request.method == 'POST':
form = BlogPostForm(request.POST)
if form.is_valid():
blog = BlogPost()
blog.author = request.user
blog.title = request.POST['title']
blog.bodytext = request.POST['bodytext']
blog.save()
messages.add_message(request, SUCCESS, 'Post Added')
return HttpResponseRedirect('/main/blog/')
else:
messages.add_message(request, SUCCESS, 'Enter a valid Post')
return HttpResponseRedirect('/main/add/')
else:
form = BlogPostForm()
return render_to_response('blog/add.html', {'form': form}, context)