本文整理汇总了Python中models.Product.key方法的典型用法代码示例。如果您正苦于以下问题:Python Product.key方法的具体用法?Python Product.key怎么用?Python Product.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Product
的用法示例。
在下文中一共展示了Product.key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import key [as 别名]
def create(request, keyname):
"Backdoor to create a new entity"
u = auth.get_current_user(request)
if u.is_admin:
p = Product(key_name=keyname)
p.name = "New Product"
p.description = "The description"
p.put()
return HttpResponseRedirect(reverse('store-edit', args=(p.key(),)))
return HttpResponseRedirect(reverse('store-index'))
示例2: Session
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import key [as 别名]
session = Session()
for site, info in SITES.items():
mdb = getattr(pymongo.Connection(), site)
pkname = SITES[site]['pk']
siteid = site2id(site)
for d in mdb.product.find():
model = d.get('model')
title = d.get('title')
key = d.get(pkname)
if model and key:
print site, model, key
p = session.query(Product).filter_by(site=site, key=key).first()
isnew = False
if not p:
isnew = True
p = Product()
p.model = model.encode('utf-8')
if title:
p.title = title.encode('utf-8')
p.key = key.encode('utf-8')
p.site = site
if isnew:
session.add(p)
session.commit()
示例3: import_products
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import key [as 别名]
def import_products():
math_story_junior = Product(title="Maths Story",
subtitle="Junior",
icon_url=MEDIA_URL + "image/icon/128x128/cd_blue.png",
display_rank=3)
math_story_primary = Product(title="Maths Story",
subtitle="Primary",
icon_url=MEDIA_URL + "image/icon/128x128/cd_blue.png",
display_rank=4)
math_story_senior = Product(title="Maths Story",
subtitle="Senior",
icon_url=MEDIA_URL + "image/icon/128x128/cd_blue.png",
display_rank=5)
english_story = Product(title="English Story",
subtitle="English",
icon_url=MEDIA_URL + "image/icon/128x128/cd_green.png",
display_rank=6)
products = [math_story_junior, math_story_primary, math_story_senior, english_story]
db.put(products)
baskets = (
Basket(
title='All Maths',
subtitle='Product collection',
icon_url=MEDIA_URL + 'image/icon/128x128/cd_bunch.png',
display_rank=0,
product_keys=[math_story_junior.key(), math_story_primary.key(), math_story_senior.key()]
),
Basket(
title='All Maths + English',
subtitle='Product collection',
icon_url=MEDIA_URL + 'image/icon/128x128/cd_bunch.png',
display_rank=0,
product_keys=[math_story_junior.key(), math_story_primary.key(), math_story_senior.key(), english_story.key()]
),
)
db.put(baskets)
subscriptions_list = (
dict(price=Decimal("29.0"),
general_sales_tax=Decimal("0.95"),
period_in_months=1,
),
dict(price=Decimal("49.0"),
general_sales_tax=Decimal("0.95"),
period_in_months=3,
#free_period_in_months=1,
),
dict(price=Decimal("149.0"),
general_sales_tax=Decimal("0.95"),
period_in_months=12,
#free_period_in_months=2,
),
)
# Now that we have keys assigned to the products,
# assign to each product a bunch of subscriptions
# and batch-dump into the datastore.
subscriptions = []
for product in products:
for subscription in subscriptions_list:
subscription['product'] = product
subscriptions.append(Subscription(**subscription))
for basket in baskets:
for subscription in subscriptions_list:
subscription['product'] = basket
subscriptions.append(Subscription(**subscription))
db.put(subscriptions)