あなたがcontrib/formtools/wizard.py
コードを読めばそれはおそらく役立ちます。それは、それはあなたがするために必要なもののよりよい感覚を与えるかなり簡単と以下です
あなた自身のフォームウィザードでオーバーライドする必要があるprocess_step
フックがあります。フォームが検証された場合(つまり、 cleaned_data
):
0私が正しくあなたの質問を理解していれば
class MyFormWizard(FormWizard):
def process_step(self, request, form, step):
if step == 0 and hasattr(form, 'cleaned_data'):
# Do special stuff
は、あなたは第二のステップは、第一のフォームからユーザーの選択に基づいて、特定のフォームを提供したいです。あなたの第2回では、次に
def process_step(self, request, form, step):
if step == 0 and hasattr(form, 'cleaned_data'):
# The initial attribute is a dictionary which maps the step number
# to a dictionary of what should be initial values.
# You can use/abuse this in a form's constructor
self.initial[1] = {'fields': {'field1': field, 'field2': another}}
:その場合は、私が最初に試してみてください、使用されるフィールドが(未テスト)最初のフォームからの結果に基づいて第二段階のためのダイナミックな一般的な形式を構築することですフォーム
class MySecondForm(forms.Form):
def __init__(self, *args, **kwargs):
super(StatBuilderForm2, self).__init__(*args, **kwargs)
for name, field in kwargs['initial']['fields'].iteritems():
self.fields[name] = field