对于问卷,我想向用户呈现一系列表单。我希望保持视图的通用性,以便它可以呈现序列中的任何表单实例。在
目前,我正在存储一个表单对象(而不是实例)的列表,并在需要呈现的时候实例化每个表单。(例如formobject = formslist[3]; form = formobject();
)。在
有没有一种更像Python的方法?我考虑过在每个表单的定义中使用getnext
函数,但是我仍然需要一个地方来列出我想要生成的表单序列。在
下一步将引入一些跳过逻辑,因此硬连接表单序列并不理想。在
也许这会有帮助。这就是我所看到的,使用getnext
函数。从第一种形式到第二种形式,但不适用于第三种形式:
def showform(request):
if 'formobj' not in locals():
formobj = StartForm
if request.method == 'POST': # If the form has been submitted...
form = formobj(request.POST)
if form.is_valid():
try:
form.save()
except:
pass
cd = form.cleaned_data
formobj = form.get_next()
form = formobj()
if formobj == 'done':
render_to_response('doneform.html', context_instance=RequestContext(request))
else:
form = formobj()
else:
form = formobj()
return render_to_response('template.html', {'form': form, 'requestpath': request.get_full_path()}, context_instance=RequestContext(request))
在表单向导步骤中,您是否查看过此文档以保存数据
Using FormWizard and saving the forms data in between before the completion of the whole process?
文章中还提到了一个名为django merlin的应用程序,它可以满足您的需要。但我个人没有用过。在
编辑
这是另一篇可能对你有帮助的帖子 Django - form wizard step by step
相关问题 更多 >
编程相关推荐