FormWizard:当拥有2个模板时,如何从步骤1继续到步骤2

时间:2013-03-13 21:56:47

标签: django django-models django-forms django-templates django-views

我在formwizard中有两个步骤。第一步是客户填写他们的特定,第二步是建立特定的。

models.py

class customer(models.Model): 
    LAST_NAME   = models.CharField(max_length = 50)
    FIRST_NAME  = models.CharField(max_length = 50)               
    ADDRESS     = models.CharField(max_length = 60, blank =True)

    def __unicode__(self):
        return '{0}' % (self)


class building(models.Model):
    CUSTOMER          = models.ForeignKey(customer, null = True, blank = True)
    BUILDING_USE         = models.CharField(max_length = 2, blank = True, choices = c.Anvendelse, default = '02')
    BUILDING_FLOORSPACE  = models.IntegerField(default=0)

    def __unicode__(self):
        return '{0}' % (self)

forms.py

class customerForm(ModelForm):
    FIRST_NAME      = forms.CharField(max_length=50)
    LAST_NAME       = forms.CharField(max_length=50)  
    ADDRESS         = forms.CharField(max_length=60)


class buildingForm(ModelForm):
    CUSTOMER            = forms.CharField(widget=forms.TextInput)
    BUILDING_FLOORSPACE = forms.CharField(widget=forms.TextInput)
    BUILDING_USE       = forms.CharField(widget=forms.TextInput)


class customerWizard(FormWizard):
    def done(self, request, form_list):
        return render_to_response('done.html', {
            'form_data': [form.cleaned_data for form in form_list],
    })

urls.py

url(r'^contact/$', customerWizard.as_view([customerForm, buildingForm])),

我实际上有两个模板customer.html和building.html 我该怎么做才能使用自己的模板。 #1将显示customer.html,#2将显示building.html。当我这样做时,它给了我customer.html,但当我提交进入下一步时,它没有显示building.html,而是显示没有样式的customer.html。

wizard.html(customer.html copy to wizard.html)     一些代码...

<div id="tabs-1">
<p>Step {{ step }} of {{ step_count }}</p>
<form action="." method="post"> 
{% csrf_token %}

 {{ form.id }} 

some codes....

<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
{{ previous_fields|safe }}
<input type="submit">
</form>

非常感谢帮助......非常需要帮助...有点想要解决这两天所有这一切,每次我做更改然后它给我一些奇怪的错误......

非常感谢你的进步。对不起我的傻q。

0 个答案:

没有答案