Wrap each form in formset with a div including unmentioned fields with django crispy forms -


i'm using following code wrap form fields of form in formset in div django crispy forms:

class operatorform(forms.modelform):     def __init__(self, *args, **kwargs):         super(operatorform, self).__init__(*args, **kwargs):             self.helper = formhelper(self)             self.helper.form_tag = false             self.helper.all().wrap_together(div, css_class="operator-form")             self.helper.render_unmentioned_fields = true      class meta:         model = operator         fields = tuple(fields_list) 

instantiating formhelper 'self' autogenerates layout without having specify fields. need because fields dynamically generated. problem delete , order fields not added layout. set render_unmentioned_fields true. setting these 2 fields @ least show in form, not wrapped rest of fields in div.

i know can manually iterate on forms in formset , wrap them div, i've been doing now, requires manual handling of non form errors of formset, done automatically crispy.

edit: updated code requested. entire class wrapped in factory method populates fields_list, can dynamically include fields. order , delete left out on purpose. automatically detected (including them results in error) , display in form, not wrapped in div.

as brian dant suggested, order , delete should added manually if included in layout. problem passed them meta class's `fields'.

class _operatorform(forms.modelform):     def __init__(self, *args, **kwargs):         super(_operatorform, self).__init__(*args, **kwargs)         self.helper = formhelper(self)         self.helper.form_tag = false         self.helper.layout.extend(['order', 'delete'])         self.helper.all().wrap_together(div, css_class="operator-form")      class meta:         model = applicationoperator         fields = tuple(fields_list) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -