Draw form buttons( using helper) after inline formset via crispy

34 Views Asked by At

I want my form to have a pair of "edit" and "return" buttons. These buttons should be at the end of the form, right after the formsets, and on the other hand, for some reason, I need the buttons to be created with crispy helper. If the form is drawn as follows, the formsets are placed under the buttons:

    {% crispy form %}
    {% for formset in inlines %}
     {{ formset.management_form }}
     {% for formss in formset %}
        {{ formss.management_form }}
        {% for fields in formss.visible_fields %}
            {{ fields|as_crispy_field }}
        {% endfor %}
     {% endfor %}
    {% endfor %}

If it is drawn as follows, the buttons will not be drawn:

{% for fields in form.visible_fields %}
        {{ fields|as_crispy_field }}
{% endfor %}

Is it possible to somehow access the helper inside the template and make it draw the pair of buttons? for example something like : {{ form.helper.inputs }}

class UpdateStaffForm(forms.ModelForm):
    class Meta:
        fields = ['first_name', 'last_name', 'is_staff']
        model = User

    helper = FormHelper()
    helper.add_input(Submit('submit', 'Edit Staff', css_class='btn-primary'))
    helper.add_input(Button('back', 'Back', css_class='btn-secondary', onClick="javascript:history.go(-1);"))
    helper.form_method = 'POST'


class UpdateStaffView(NamedFormsetsMixin, UpdateWithInlinesView):
    template_name = "pages/staff/update.html"
    model = User
    form_class = UpdateStaffForm
    success_url = "/staff/"
    inlines = [StaffInline, ]
0

There are 0 best solutions below