当前位置: 首页>>代码示例>>Python>>正文


Python Image.reward方法代码示例

本文整理汇总了Python中models.Image.reward方法的典型用法代码示例。如果您正苦于以下问题:Python Image.reward方法的具体用法?Python Image.reward怎么用?Python Image.reward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Image的用法示例。


在下文中一共展示了Image.reward方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: manage_reward

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import reward [as 别名]
def manage_reward(request, key):
	form = None
	riddle_form = None
	condition_form = None
	
	try:
		#loading existing reward
		reward = Reward.objects.get(key=key)
	except Reward.DoesNotExist:
		#creating new reward, initialize variables
		reward = Reward()
		reward.key = key
	
	riddle = reward.riddle_set.all()
	if riddle.count() == 0:
		riddle = Riddle()
	else:
		riddle = riddle[0]
	
	condition = reward.condition_set.all()
	if condition.count() == 0:
		condition = Condition()
	else:
		condition = condition[0]

	if request.method == 'POST':
		form = RewardManageForm(instance=reward, data=request.POST)
		if form.is_valid():
			reward = form.save()
			blob_infos = get_blobinfo_from_post(request)
			for blob_info in blob_infos:
				#print "blobkey: " + str(blob_info.key())
				image = Image()
				image.blob_key = str(blob_info.key())
				image.reward = reward
				image.save()
		riddle.reward = reward
		riddle_form = RiddleManageForm(instance=riddle, data=request.POST) 
		if riddle_form.is_valid():
			riddle_form.save()
		condition.reward = reward
		condition_form = ConditionManageForm(instance=condition, data=request.POST) 
		if condition_form.is_valid():
			condition_form.save()
		
	images = list(reward.image_set.all())
	images.append(Image())
	
	if form is None:
		form = RewardManageForm(instance=reward)
	
	image_forms = []
	for image in images:
		image_forms.append(ImageManageForm(instance=image))
	
	if riddle_form is None:
		riddle_form = RiddleManageForm(instance=riddle)
	
	if condition_form is None:
		condition_form = ConditionManageForm(instance=condition)

	url = reverse('manage_reward', kwargs={'key': key})
	upload_url = blobstore.create_upload_url(url)

	return render_to_response('reward/manage.html', {'upload_url': upload_url, 'form': form, 'reward': reward, 'image_forms':image_forms, 'riddle_form':riddle_form, 'condition_form':condition_form }, context_instance=RequestContext(request))
开发者ID:laDanz,项目名称:adventskalender,代码行数:67,代码来源:views.py


注:本文中的models.Image.reward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。