我在django向导窗体上遇到了一个很大的问题。跳过步骤x到步骤y并验证步骤x数据
我有3个步骤。第二步可以包含或不包含数据。最后一步是文件上传步骤。
在WizardForm类,我overrided的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)
正如你看到的,如果没有问题,我跳过第二步(against_indication)进入下一步骤(处方)。
问题出现在这里。当最后一步渲染时,向导窗体中没有足够的数据。在ddt的要求是这样的: with skip step。 因此,如果我上传文件,它会填充反对数据而不是处方数据,并重新渲染我最后一步...
我试图做所有这些,而不跳过第二步,看看如何看看ddt的要求: without skip step。
有人有一个解决方案,允许有正确的数据时,我跳过步骤,PLZ?
感谢您的回答进一步
谢谢@IanPrice!这个使用condition_dict的例子比官方的django例子更真实。它拯救了我的一天:) –
很好听!是的,这些文档对FW来说确实不是很好。 –
如果我能够帮助,将此标记为答案并upvoting是赞赏:) –