Crispy formhelper and formset: access form instance data

14 Views Asked by At

I've a formset and i've created an helper to render the formset.

The form

class VulnerabilityForm(forms.ModelForm):

    class Meta:
        model = Vulnerability
        fields = ('is_selected',)

The helper

class VulnerabiltyHelper(FormHelper):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.form_method = 'post'
        self.layout = Layout(
            Row(
                Column(HTML('{{form.instance}}'),
                       css_class='col-8'),
                Column(Field('is_selected'),
                       css_class='col-4')
            )
        )
        self.render_required_fields = True

What I want to have is to print the model.name in html, and next to it the button of the bool.

How can i access the form.instance data in a formset when it's rendered? Is that possible? how could do I do that?

Edit, This actually prints what expected

  {{ formset.management_form|crispy }}
    {% for form in formset %}
        {% crispy form helper %}
    {% endfor %}

This, does not render the instance

 {% crispy formset helper %}

does crispy tag somehow name the rendering form not form ?

0

There are 0 best solutions below