本文整理汇总了Python中models.Activity.average_price方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.average_price方法的具体用法?Python Activity.average_price怎么用?Python Activity.average_price使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Activity
的用法示例。
在下文中一共展示了Activity.average_price方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import average_price [as 别名]
def post(self, request, format=None):
date = request.DATA.get('date')
try:
activity = Activity.objects.get(name=request.DATA.get('activity'))
except Activity.DoesNotExist:
activity = Activity(name=request.DATA.get('activity'), average_price=0)
activity.save()
p = Process(date=request.DATA.get('date'), activity=activity, average_price=0)
p.save()
consumer_list = json.loads(request.DATA.get('list'))
user_to_be_saved = []
total = 0
try:
for num, i in enumerate(consumer_list):
name = i.get('name')
prepay = i.get('prepay')
consume = i.get('consume')
#check name
user = User.objects.get(name=name)
p.participants.add(user)
#user money
user.remain += prepay - consume
user_to_be_saved.append(user)
total += consume
#send email
except:
print sys.exc_info()
p.delete()
return Response(status=404)
#caculate the average price of process
p.average_price =total/(num +1)
#caculate the average price of activity
if p.average_price == 0:
activity.average_price = p.average_price
else:
activity.average_price = (p.average_price + activity.average_price)/2
p.save()
for i in user_to_be_saved:
i.save()
return Response({"detail":"success"} ,status=200)