1

正如我發現重複自己,我想在我的幫手中使用Meta.fields,而不是複製兩次我的字段列表,只是爲了讓StrictButton位於我的表單的底部。這裏是我的形式:StrictButton在模型的底部

class ContactForm(forms.ModelForm): 

def __init__(self, *args, **kwargs): 
    super(ContactForm, self).__init__(*args, **kwargs) 
    self.helper = FormHelper() 
    self.helper.form_class = 'form-horizontal' 
    self.helper.label_class = "col-lg-2" 
    self.helper.field_class = 'col-lg-8' 
    self.helper.layout = Layout(
     self.Meta.fields + (
     StrictButton('Send', css_class='btn-default', type='submit'), 
    ) 
    ) 
    self.helper.form_method = 'post' 
    self.helper.form_action = '' 

    class Meta: 
     model = Contact 
     fields = ('title', 'name', 'firstname', 'address', 'mail', 'tel', 
       'mobile', 'login', 'password', 'note') 

,但此行

$(self.Meta.fields +(StrictButton( '發送',css_class = 'BTN-默認',類型= '提交',))

是行不通的。它提出了

無法解析表單字段 '(' 標題 ' '名', '姓名', '地址', '郵件', '電話','手機','登錄','密碼','備註',)'

難道我真的不得不復制我的領域,爲了讓我的表格StrictButton?

+0

:d對不起,我沒有測試它,但解包是寫的想法,加上你的答案,並接受它=) – madzohan 2014-11-14 16:14:06

+0

這是一個好主意,它給我的解決方案,爲什麼不要編輯它而不是刪除它! – 2014-11-14 16:21:10

回答

0

感謝madzohan,我需要解壓Meta.fields。什麼工作原理是:

self.helper.layout = Layout(
     *(self.Meta.fields + (StrictButton('Send', css_class='btn-default', type='submit'),)) 
    )