2017-03-13 4 views
0

フォームを複数のページに分割したdjangoフォームウィザードを使用しようとしています。私はドキュメントから何かをまとめようとしている。だから、現在、私は次の形式を持っている:フォームウィザードは次のボタンを表示しません

class DummyForm(ModelForm): 
    class Meta: 
     model = DummyModel 
     fields = ['name', 'description', 'time_points'] 

    def __init__(self, *args, **kwargs): 
     super(DummyForm, self).__init__(*args, **kwargs) 
     self.helper = FormHelper(self) 
     self.helper.form_class = 'form-horizontal' 
     self.helper.label_class = 'col-sm-2' 
     self.helper.field_class = 'col-sm-10' 
     self.helper.layout = Layout(
      Field('name'), 
      Field('description'), 
      Field('time_points')) 


class OtherForm(ModelForm): 
    class Meta: 
     model = DummyModel 
     fields = ['more_text'] 

    def __init__(self, *args, **kwargs): 
     super(DummyForm, self).__init__(*args, **kwargs) 
     self.helper = FormHelper(self) 
     self.helper.form_class = 'form-horizontal' 
     self.helper.label_class = 'col-sm-2' 
     self.helper.field_class = 'col-sm-10' 
     self.helper.layout = Layout(
      Field('More_text')) 

私は次のように構成されたビューとURLを持っている:

views.py

from django.http import HttpResponseRedirect 
class ContactWizard(SessionWizardView): 
    def get_template_names(self): 
     return "test.html" 

    def done(self, form_list, **kwargs): 
     return HttpResponseRedirect('index') 

urls.py

url(r'^contact/$', views.ContactWizard.as_view([DummyForm, OtherForm])) 

最終

{% extends "base.html" %} 
{% load i18n %} 

{% block content %} 
<p>Step {{ wizard.steps.current }} of {{ wizard.steps.count }}</p> 
<form action="." method="post">{% csrf_token %} 
<table> 
{{ wizard.management_form }} 
{% if wizard.form.forms %} 
    {{ wizard.form.management_form }} 
    {% for form in wizard.form.forms %} 
     {{ form }} 
    {% endfor %} 
{% else %} 
    {{ wizard.form }} 
{% endif %} 
{% if wizard.steps.prev %} 
<button name="wizard_prev_step" value="{{ wizard.steps.first }}">{% trans "first step" %}</button> 
<button name="wizard_prev_step" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button> 
{% endif %} 
</table> 
<input type="submit"> 
</form> 
{% endblock %} 

私は完全にテンプレートコードを理解していないが、私は、次のフォームに移動するボタンを期待していた:LY、私のtest.htmlというテンプレートは次のようになります。代わりに、スクリーンショットに表示されているように、送信ボタンが表示されます。

誰かが私が間違って行ったことを見ることができますか?フォームは最初のフォームをレンダリングするように見え、ナビゲートする方法はありません。ドキュメントを読む

enter image description here

答えて

1

、フォームウィザードは、次のステップにユーザーを移動します。

あなたは、あなたが

<input type="submit" value="Next"> 
+1

<input type="submit"> 

を変更することができます送信ボタンの名前を変更したい場合は、私は私が 'コピーpaste'エラー気づいた:スーパー(DummyForm、自己を).__ init __(* args、** kwargs)はsuper(OtherForm、self)でなければなりません.____ init __(* args、** kwargs) – Luca

0

、私はthisに締結しました。これはあなたのurls.pyにあなたがそれに変更する必要があることを意味します送信ボタンを押すと、フォームが有効であれば

urlpatterns = [ 
    url(r'^contact/$', views.ContactWizard.as_view([DummyForm, OtherForm], instance_dict=[DummyForm(), OtherForm()])) 
], 
関連する問題