title: Django - how to collapse forms like in the django admin
body: <p>I use <a href="http://pypi.python.org/pypi/django-form-utils" rel="nofollow">django-form-utils</a> to generate BetterModelForm with fieldsets similar to the django admin. With BetterModelForm its possible to associate CSS with fieldset with the 'classes' option. I would like to know how I could collapse the fieldset of my form like we can do it in Django-Admin.</p>
  
  <p>forms.py:</p>
  
  <pre><code>class ezAppOptionFormSet(BetterModelForm):
  
  
      class Meta:
          model = EzApp
          fieldsets = [('App options:', {'fields': ['level', 'center_1', 'center_2', 'width', 'height'], 'classes': ['collapse']}),
                  ('Colors:', {'fields': ['color'], 'classes': ['collapse']})
                  ]
  </code></pre>
  
  <p>template.html:</p>
  
  <pre><code>    &lt;form method="post" action="." encrypt="multipart/form-data"&gt;{% csrf_token %}
          &lt;b&gt;App name: {{ App_title }}&lt;/b&gt;
          {% if formset.non_field_errors %}{{ formset.non_field_errors }}{% endif %}
          {% for fieldset in formset.fieldsets %}
              &lt;fieldset class="{{ fieldset.classes }}"&gt;
              {% if fieldset.legend %}
                  &lt;legend&gt;{{ fieldset.legend }}&lt;/legend&gt;
              {% endif %}
              {% if fieldset.description %}
              &lt;p class="description"&gt;{{ fieldset.description }}&lt;/p&gt;
              {% endif %}
              &lt;ul&gt;
              {% for field in fieldset %}
                  {% if field.is_hidden %}
                      {{ field }}
                  {% else %}
                      &lt;li{{ field.row_attrs }}&gt;
                      {{ field.errors }}
                      {{ field.label_tag }}&lt;br&gt;
                      {{ field }}
                      &lt;/li&gt;
                  {% endif %}
              {% endfor %}
              &lt;/ul&gt;
              &lt;/fieldset&gt;
          {% endfor %}
  </code></pre>