使用ModelForm的Django Crispy表单,没有类型没有属性字段,wrap_together

时间:2018-01-15 16:36:00

标签: python django django-crispy-forms

我是酥脆的形式的新手,我试图在表格中加入一些布局,将它们分成三组,然后就像把它们放在一些面板中一样(我使用boostrap3)

这是我的forms.py

class EditSiteForm(forms.ModelForm):

    class Meta:
        model = SiteData
        fields = ['location', 'site_type', 'bgp_as', 'opening_date','last_hw_refresh_date','is_live',
                    'tel','address','town','postcode',
                    'regional_manager','regional_manager_tel','assistant_manager','assistant_manager_tel' ,'duty_manager','duty_manager_tel']

    helper = FormHelper()
    helper.form_method = 'POST'
    helper.add_input(Submit('Save', 'Save', css_class='btn-primary'))
    helper[0:5].wrap_together(Field, 'Details')
    helper[6:9].wrap_together(Field, 'Address')
    helper[10:15].wrap_together(Field, 'Showroom Contacts')

当我加载页面时,我得到了     回溯:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/itapp/itapp/sites/views.py" in edit_site
  829.     from sites.forms import EditSiteForm

File "/itapp/itapp/sites/forms.py" in <module>
  35. class EditSiteForm(forms.ModelForm):

File "/itapp/itapp/sites/forms.py" in EditSiteForm
  46.     helper[0:5].wrap_together(Field, 'Details')

File "/usr/local/lib/python3.6/site-packages/crispy_forms/layout_slice.py" in wrap_together
  107.                 LayoutClass, self.layout.fields[self.slice], *args, **kwargs

Exception Type: AttributeError at /sites/edit/7
Exception Value: 'NoneType' object has no attribute 'fields'

是不支持crispy的modelform?我是否需要先手动发出每个字段?

由于

0 个答案:

没有答案