本文整理汇总了Python中models.Blog.category方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.category方法的具体用法?Python Blog.category怎么用?Python Blog.category使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Blog
的用法示例。
在下文中一共展示了Blog.category方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testdb_init
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import category [as 别名]
def testdb_init():
# db clear
t1 = Tag(title="emacs")
t2 = Tag(title="python")
t1.put()
t2.put()
c1 = Category(title='program')
c2 = Category(title='edit')
c1.put()
c2.put()
b1 = Blog(title='first blog')
b1.context = "this is my first blog, hello world"
b1.put()
b2 = Blog(title="second blog")
b2.context = "this is my second blog, hello python"
b2.tags = [t1.key, t2.key]
b2.put()
b3 = Blog(title="third blog")
b3.context = "this is my third blog, hello python"
b3.tags = [t1.key,]
b3.category = c2.key
b3.put()
b4 = Blog(title="fourth blog")
b4.context = "this is my fourth blog, hello python"
b4.tags = [t2.key,]
b4.category = c1.key
b4.put()
示例2: create
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import category [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)
示例3: create
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import category [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)