StrictButton位于modelforms的底部

时间:2014-11-14 12:30:04

标签: django python-2.7 twitter-bootstrap-3 django-crispy-forms

当我发现重复自己时,我想在我的助手中使用Meta.fields而不是复制两次我的字段列表,只是为了让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-default',type ='submit',))

只是不起作用。它提出了

  

无法解析表单字段'('title','name','firstname','address','mail','telephone','mobile','login','password','note', )”

我是否真的必须再次复制我的字段才能将StrictButton放到我的表单中?

1 个答案:

答案 0 :(得分:0)

感谢madzohan,我需要解压缩Meta.fields。有效的是:

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