【发布时间】:2016-01-20 16:09:10
【问题描述】:
我实际上在 django 向导表单上遇到了一个大问题。
我有 3 个步骤。第二步可以包含或不包含数据。最后一步是文件上传步骤。
在 WizardForm 类中,我重写了 get_context_data 方法并将其包含在其中:
if self.steps.current == 'against_indication':
questions = None
try:
# get the machine
machine_id = self.kwargs['pk']
machine = Machine.objects.get(pk=int(machine_id))
# check if there is against indications
if machine.type_question is False:
questions = YhappsQuestion.objects.filter(type_modalite=machine.type)
else:
questions = CustomQuestion.objects.filter(machine=machine)
except Machine.DoesNotExist:
pass
if len(questions) == 0:
# we modify the form wizard to skip against indication step
self.render_next_step(form, **kwargs)
#self.render_goto_step(step='against_indication', goto_step='prescription', **kwargs)
如您所见,如果没有问题,我跳过第二步(反对指示)进入下一步(处方)。
问题出现在这里。渲染最后一步时,向导表单中没有足够的数据。在 ddt 的请求中有它: with skip step。 因此,如果我上传文件,它将填充反对指示数据而不是处方数据,并重新渲染我最后一步...
我尝试在不跳过第二步的情况下完成所有这些操作,看看 ddt 的请求如何: without skip step.
当我跳过步骤时,有人有一个解决方案允许拥有正确的数据,请?
感谢您的进一步回答
【问题讨论】: