Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect empty formset in template

I am rendering a formset in a template. How can I write a condition such that the page displays the sentence "Nothing to show" if the formset has no elements?

The following does not work:

{% if formset %}
    {{ formset }}
{% else %}
    <p>Nothing to show</p>
{% endif %}
like image 252
mimo Avatar asked Dec 12 '22 02:12

mimo


1 Answers

I just found the answer by myself... It works with formset.forms:

{% if formset.forms %}
    {{ formset }}
{% else %}
    <p>Nothing to show</p>
{% endif %}
like image 177
mimo Avatar answered Dec 22 '22 17:12

mimo