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


Python TestForm.save方法代码示例

本文整理汇总了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))
开发者ID:jpihl,项目名称:plotato,代码行数:20,代码来源:views.py

示例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/')
开发者ID:uraharaLL,项目名称:recordbook,代码行数:45,代码来源:views.py

示例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))
开发者ID:jpihl,项目名称:plotato,代码行数:18,代码来源:views.py


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