本文整理匯總了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)