本文整理匯總了Python中model.Shop.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Shop.save方法的具體用法?Python Shop.save怎麽用?Python Shop.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類model.Shop
的用法示例。
在下文中一共展示了Shop.save方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from model import Shop [as 別名]
# 或者: from model.Shop import save [as 別名]
def post(self, cid):
try:
category = Category.get(id = cid)
except:
self.flash("此分類不存在")
self.redirect("/admin/addshop")
return
categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == cid)
cover = self.get_argument("cover", None)
pics = self.get_argument("pics", None)
name = self.get_argument("name", None)
ename = self.get_argument("ename", None)
price = str(float(str(self.get_argument("price", 0.0))))
level = int(self.get_argument("level", 3))
resume = self.get_argument("resume", "")
intro = self.get_argument("intro", "")
prompt = self.get_argument("prompt", "")
views = int(self.get_argument("views", 0))
try:
shop = Shop()
shop.name = name
shop.ename = ename
shop.cid = cid
shop.level = level
shop.resume = resume
shop.intro = intro
shop.prompt = prompt
shop.price = price
shop.views = views
args = {}
for categoryattr in categoryattrs:
caid = str(categoryattr.id)
args['attr_' + caid] = self.get_argument('attr_' + caid, '')
shop.args = simplejson.dumps(args)
if pics:
pics = pics.split(',')
pics = [pic.replace('/upload/', '') for pic in pics]
if not cover:
cover = pics[0]
if not cover:
cover = ''
shop.cover = cover.replace('/upload/', '')
shop.validate()
shop.save()
if isinstance(pics, list):
for pic in pics:
shoppic = ShopPic()
shoppic.sid = shop.id
shoppic.path = pic
shoppic.save()
self.flash(u"添加商品%s成功" % name, 'ok')
if category.id == 2:
self.redirect("/admin/shops")
else:
self.redirect("/admin/addshopattr/" + str(shop.id))
return
except Exception, ex:
self.flash(str(ex))