本文整理汇总了Python中models.Category.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Category.get_by_key_name方法的具体用法?Python Category.get_by_key_name怎么用?Python Category.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.get_by_key_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_by_key_name [as 别名]
def post(self, subdomain):
namespace_manager.set_namespace(subdomain)
visible = False
if self.request.get('visible') == 'yes':
visible = True
name = self.request.get('name')
categories = self.request.get('category').split(',')
logging.info(categories)
cat_refs = []
for category in categories:
logging.info(category)
if Category.get_by_key_name(category):
cat_refs.append(Category.get_by_key_name(category).key())
logging.info(cat_refs)
entity = Product(key_name=name,
name=name,
shop_id=Shop.get_by_key_name(subdomain),
stock=int(self.request.get('qty')),
description=self.request.get('description'),
price=float(self.request.get('price')),
tags=self.request.get('tags').split(','),
video=self.request.get('video'),
visible=visible,
categories=cat_refs
)
entity.put()
self.redirect(webapp2.uri_for('addproducts'))
示例2: delete_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_by_key_name [as 别名]
def delete_category(category_name):
"""Delete an post object"""
category = Category.get_by_key_name(category_name)
try:
category.delete()
flash(u"Example %s successfully deleted." % category.name, "success")
return redirect(url_for("list_categories"))
except CapabilityDisabledError:
flash(u"App Engine Datastore is currently in read-only mode.", "info")
return redirect(url_for("list_categories"))
示例3: edit_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_by_key_name [as 别名]
def edit_category(category_name):
category = Category.get_by_key_name(category_name)
form = CategoryForm(obj=category)
if form.validate_on_submit():
form.populate_obj(category)
try:
category.put()
flash(u"Example %s successfully saved." % category.name, "success")
return redirect(url_for("list_categories"))
except CapabilityDisabledError:
flash(u"App Engine Datastore is currently in read-only mode.", "info")
return redirect(url_for("list_categories"))
return render_template("edit_category.html", form=form, category_name=category.id)