本文整理汇总了Python中models.Test.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Test.delete方法的具体用法?Python Test.delete怎么用?Python Test.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Test
的用法示例。
在下文中一共展示了Test.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import delete [as 别名]
def post(self, request):
form = UploadFileForm(request.POST, request.FILES)
msg = ''
if form.is_valid():
test = Test(
start_time = convert_time(form.cleaned_data['start']),
end_time = convert_time(form.cleaned_data['end']),
author_id = UserProfile.objects.get(user__id=request.user.id),
time = int(form.cleaned_data['time'])
)
test.save()
try:
test.room = Room.objects.get(id=form.cleaned_data.get('room'))
except:
test.room = None
finally:
test.save()
try:
self.handle_uploaded_file(test.id, request.FILES['file'])
except:
test.delete()
msg = {'error': 'Wystąpił konflikt terminów. Test nie został dodany.'}
return render(request, self.template_name, {'form': form, 'msg': msg})
else:
test.name = self.get_test_name_from_file(test.id)
test.save()
return HttpResponseRedirect(reverse('tests'))
else:
msg = {'error': u'Wystąpił błąd podczas ładowania pliku.'}
form = UploadFileForm()
return render(request, self.template_name, {'form': form, 'msg': msg})