本文整理汇总了Python中models.Category.slug方法的典型用法代码示例。如果您正苦于以下问题:Python Category.slug方法的具体用法?Python Category.slug怎么用?Python Category.slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.slug方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import slug [as 别名]
def post(self):
json = {}
if not self.current_user:
json = {
'error': 1,
'msg': self._('Access denied')
}
self.write(json)
return
title = self.get_argument('title', None)
slug = self.get_argument('slug', None)
description = self.get_argument('description', '')
# valid arguments
if not title:
json = {
'error': 1,
'msg': self._('Title field can not be empty')
}
self.write(json)
return
if not slug:
json = {
'error': 1,
'msg': self._('Slug field can not be empty')
}
self.write(json)
return
elif self.get_category_by_slug(slug):
json = {
'error': 1,
'msg': self._('Slug already exists')
}
self.write(json)
return
# create category
category = Category()
category.title = title
category.slug = slug
category.description = description
self.db.add(category)
self.db.commit()
# delete cache
keys = ['CategoryList', 'SystemStatus']
self.cache.delete_multi(keys)
json = {
'error': 0,
'msg': self._('Successfully created'),
'category': {
'id': category.id,
'title': category.title,
'slug': category.slug,
'description': category.description,
'permalink': category.permalink,
'post_count': category.post_count
}
}
self.write(json)
示例2: add_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import slug [as 别名]
def add_category(request):
if request.method == "POST":
category = Category()
category.name = request.POST["name"]
category.slug = request.POST["slug"]
category.put()
return HttpResponseRedirect("/category/add")
return render_to_response("add_category.html", context_instance=RequestContext(request))
示例3: add_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import slug [as 别名]
def add_category(request):
if request.method == 'POST':
category = Category()
category.name = request.POST['name']
category.slug = request.POST['slug']
category.put();
return HttpResponseRedirect('/category/add')
return render_to_response('add_category.html', context_instance=RequestContext(request))