Index: django/forms/formsets.py
===================================================================
--- django/forms/formsets.py	(revision 12662)
+++ django/forms/formsets.py	(working copy)
@@ -321,11 +321,11 @@
         return mark_safe(u'\n'.join([unicode(self.management_form), forms]))
 
 def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
-                    can_delete=False, max_num=0):
+                    can_delete=False, max_num=0, classes=None):
     """Return a FormSet for the given form class."""
     attrs = {'form': form, 'extra': extra,
              'can_order': can_order, 'can_delete': can_delete,
-             'max_num': max_num}
+             'max_num': max_num, 'classes':classes or []}
     return type(form.__name__ + 'FormSet', (formset,), attrs)
 
 def all_valid(formsets):
Index: django/forms/models.py
===================================================================
--- django/forms/models.py	(revision 12662)
+++ django/forms/models.py	(working copy)
@@ -643,7 +643,7 @@
         super(BaseModelFormSet, self).add_fields(form, index)
 
 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
-                         formset=BaseModelFormSet,
+                         formset=BaseModelFormSet, classes=None,
                          extra=1, can_delete=False, can_order=False,
                          max_num=0, fields=None, exclude=None):
     """
@@ -652,7 +652,8 @@
     form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
                              formfield_callback=formfield_callback)
     FormSet = formset_factory(form, formset, extra=extra, max_num=max_num,
-                              can_order=can_order, can_delete=can_delete)
+                              can_order=can_order, can_delete=can_delete,
+                              classes=classes or [])
     FormSet.model = model
     return FormSet
 
@@ -794,7 +795,7 @@
 
 def inlineformset_factory(parent_model, model, form=ModelForm,
                           formset=BaseInlineFormSet, fk_name=None,
-                          fields=None, exclude=None,
+                          fields=None, exclude=None, classes=None,
                           extra=3, can_order=False, can_delete=True, max_num=0,
                           formfield_callback=lambda f: f.formfield()):
     """
@@ -817,6 +818,7 @@
         'fields': fields,
         'exclude': exclude,
         'max_num': max_num,
+        'classes': classes or [],
     }
     FormSet = modelformset_factory(model, **kwargs)
     FormSet.fk = fk
Index: django/contrib/admin/options.py
===================================================================
--- django/contrib/admin/options.py	(revision 12662)
+++ django/contrib/admin/options.py	(working copy)
@@ -1188,6 +1188,7 @@
     verbose_name = None
     verbose_name_plural = None
     can_delete = True
+    classes = []
 
     def __init__(self, parent_model, admin_site):
         self.admin_site = admin_site
@@ -1204,6 +1205,8 @@
         js = ['js/jquery.min.js', 'js/inlines.min.js']
         if self.prepopulated_fields:
             js.append('js/urlify.js')
+        if 'collapse' in self.classes:
+            js.append('js/collapse.min.js')
         if self.filter_vertical or self.filter_horizontal:
             js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
         return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
@@ -1234,6 +1237,7 @@
             "extra": self.extra,
             "max_num": self.max_num,
             "can_delete": self.can_delete,
+            "classes": self.classes,
         }
         defaults.update(kwargs)
         return inlineformset_factory(self.parent_model, self.model, **defaults)
Index: django/contrib/admin/templates/admin/edit_inline/tabular.html
===================================================================
--- django/contrib/admin/templates/admin/edit_inline/tabular.html	(revision 12662)
+++ django/contrib/admin/templates/admin/edit_inline/tabular.html	(working copy)
@@ -2,7 +2,7 @@
 <div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
   <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
 {{ inline_admin_formset.formset.management_form }}
-<fieldset class="module">
+<fieldset class="module {% for class in inline_admin_formset.formset.classes %} {{class}}{% endfor %}">
    <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
    {{ inline_admin_formset.formset.non_form_errors }}
    <table>
Index: django/contrib/contenttypes/generic.py
===================================================================
--- django/contrib/contenttypes/generic.py	(revision 12662)
+++ django/contrib/contenttypes/generic.py	(working copy)
@@ -335,7 +335,7 @@
 def generic_inlineformset_factory(model, form=ModelForm,
                                   formset=BaseGenericInlineFormSet,
                                   ct_field="content_type", fk_field="object_id",
-                                  fields=None, exclude=None,
+                                  fields=None, exclude=None, classes=None,
                                   extra=3, can_order=False, can_delete=True,
                                   max_num=0,
                                   formfield_callback=lambda f: f.formfield()):
@@ -360,7 +360,7 @@
         exclude = [ct_field.name, fk_field.name]
     FormSet = modelformset_factory(model, form=form,
                                    formfield_callback=formfield_callback,
-                                   formset=formset,
+                                   formset=formset, classes=classes or [],
                                    extra=extra, can_delete=can_delete, can_order=can_order,
                                    fields=fields, exclude=exclude, max_num=max_num)
     FormSet.ct_field = ct_field
@@ -394,7 +394,8 @@
             "can_order": False,
             "fields": fields,
             "max_num": self.max_num,
-            "exclude": exclude
+            "exclude": exclude,
+            "classes": classes,
         }
         return generic_inlineformset_factory(self.model, **defaults)
 
