本文整理汇总了Python中forms.TestForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python TestForm.save方法的具体用法?Python TestForm.save怎么用?Python TestForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.TestForm
的用法示例。
在下文中一共展示了TestForm.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_test
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import save [as 别名]
def edit_test(request, test_id):
""" Edit Test.
"""
test = get_object_or_404(Test, pk=test_id)
if request.method == "POST":
form = TestForm(request.POST, instance=test)
else:
form = TestForm(instance=test)
if form.is_valid(): # All validation rules pass
form.save()
messages.add_message(request, messages.INFO, 'The test has been successfully modified.')
return redirect(details_test, test_id=test_id)
return render_to_response('form.html',
{'form' : form,
'project' : test.project},
context_instance=RequestContext(request))
示例2: testEdit
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import save [as 别名]
def testEdit(request, mode, id = 0):
render = render_options(request)
if request.method == 'GET':
if mode == 'add':
form = TestForm()
elif mode == 'edit':
form = TestForm(instance = get_object_or_404(Test, id = id))
else:
get_object_or_404(Test, id = id).delete()
return HttpResponseRedirect('/tests/test/')
form.fields['subject'].queryset = request.user.subjects
form.fields['grades'].queryset = request.user.grades
del form.fields['share']
render['form'] = form
return render_to_response('tests/test.html', render)
else:
if mode == 'add':
form = TestForm(request.POST)
if form.is_valid():
test = form.save(commit = False)
test.teacher = request.user
test.save()
form.save_m2m()
return HttpResponseRedirect('/tests/test/')
else:
form.fields['subject'].queryset = request.user.subjects
form.fields['grades'].queryset = request.user.grades
del form.fields['share']
render['form'] = form
return render_to_response('tests/test.html', render)
elif mode == 'edit':
form = TestForm(request.POST, instance = get_object_or_404(Test, id = id))
if form.is_valid():
form.save()
return HttpResponseRedirect('/tests/test/')
else:
form.fields['subject'].queryset = request.user.subjects
form.fields['grades'].queryset = request.user.grades
del form.fields['share']
render['form'] = form
return render_to_response('tests/test.html', render)
else:
return HttpResponseRedirect('/tests/test/')
示例3: create_test
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import save [as 别名]
def create_test(request, project_id):
""" Create a new Test.
"""
project = get_object_or_404(Project, pk=project_id)
form = TestForm(request.POST or None)
if form.is_valid():
new_test = form.save(commit=False) # returns unsaved instance
new_test.project = project
new_test.save() # real save to DB.
messages.add_message(request, messages.SUCCESS, 'The test has been successfully created.')
return redirect(details_project, project_id=project_id)
return render_to_response('form.html',
{'form' : form,
'project' : project},
context_instance=RequestContext(request))