本文整理汇总了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))