Index: django/forms/formsets.py
===================================================================
--- django/forms/formsets.py	(revision 12873)
+++ django/forms/formsets.py	(working copy)
@@ -329,11 +329,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=None):
+                    can_delete=False, max_num=None, 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 12873)
+++ django/forms/models.py	(working copy)
@@ -647,7 +647,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=None, fields=None, exclude=None):
     """
@@ -656,7 +656,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
 
@@ -798,7 +799,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=None,
                           formfield_callback=lambda f: f.formfield()):
     """
@@ -821,6 +822,7 @@
         'fields': fields,
         'exclude': exclude,
         'max_num': max_num,
+        'classes': classes or [],
     }
     FormSet = modelformset_factory(model, **kwargs)
     FormSet.fk = fk
Index: django/contrib/admin/media/css/forms.css
===================================================================
--- django/contrib/admin/media/css/forms.css	(revision 12873)
+++ django/contrib/admin/media/css/forms.css	(working copy)
@@ -125,21 +125,21 @@
 
 /* COLLAPSED FIELDSETS */
 
-fieldset.collapsed * {
+fieldset.collapsed *, div.collapsed * {
     display: none;
 }
 
-fieldset.collapsed h2, fieldset.collapsed {
+fieldset.collapsed h2, fieldset.collapsed, div.collapsed h2, div.collapsed {
     display: block !important;
 }
 
-fieldset.collapsed h2 {
+fieldset.collapsed h2, div.collapsed h2 {
     background-image: url(../img/admin/nav-bg.gif);
     background-position: bottom left;
     color: #999;
 }
 
-fieldset.collapsed .collapse-toggle {
+.collapse-toggle {
     background: transparent;
     display: inline !important;
 }
Index: django/contrib/admin/media/js/collapse.min.js
===================================================================
--- django/contrib/admin/media/js/collapse.min.js	(revision 12873)
+++ django/contrib/admin/media/js/collapse.min.js	(working copy)
@@ -1,2 +1,2 @@
-(function(a){a(document).ready(function(){a("fieldset.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="fieldsetcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});a("fieldset.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("fieldset").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("fieldset").addClass("collapsed");
-return false})})})(jQuery);
+(function(a){a(document).ready(function(){a("div.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="divcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});a("fieldset.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="fieldsetcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});
+a("fieldset.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("fieldset").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("fieldset").addClass("collapsed");return false});a("div.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("div").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("div").addClass("collapsed");return false})})})(jQuery);
Index: django/contrib/admin/media/js/collapse.js
===================================================================
--- django/contrib/admin/media/js/collapse.js	(revision 12873)
+++ django/contrib/admin/media/js/collapse.js	(working copy)
@@ -1,5 +1,14 @@
 (function($) {
 	$(document).ready(function() {
+	    $("div.collapse").each(function(i, elem) {
+			// Don't hide if fields in this fieldset have errors
+            if ( $(elem).find("div.errors").length == 0 ) {
+				$(elem).addClass("collapsed");
+				$(elem).find("h2").first().append(' (<a id="divcollapser' +
+					i +'" class="collapse-toggle" href="#">' + gettext("Show") +
+					'</a>)');
+            }
+		});
 		// Add anchor tag for Show/Hide link
 		$("fieldset.collapse").each(function(i, elem) {
 			// Don't hide if fields in this fieldset have errors
@@ -10,6 +19,8 @@
 					'</a>)');
 			}
 		});
+
+		
 		// Add toggle to anchor tag
 		$("fieldset.collapse a.collapse-toggle").toggle(
 			function() { // Show
@@ -23,5 +34,17 @@
 				return false;
 			}
 		);
+		$("div.collapse a.collapse-toggle").toggle(
+			function() { // Show
+				$(this).text(gettext("Hide"));
+				$(this).closest("div").removeClass("collapsed");
+				return false;
+			},
+			function() { // Hide
+				$(this).text(gettext("Show"));
+				$(this).closest("div").addClass("collapsed");
+				return false;
+			}
+		);
 	});
 })(jQuery);
Index: django/contrib/admin/options.py
===================================================================
--- django/contrib/admin/options.py	(revision 12873)
+++ django/contrib/admin/options.py	(working copy)
@@ -1184,6 +1184,7 @@
     verbose_name = None
     verbose_name_plural = None
     can_delete = True
+    classes = []
 
     def __init__(self, parent_model, admin_site):
         self.admin_site = admin_site
@@ -1200,6 +1201,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])
@@ -1230,6 +1233,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/stacked.html
===================================================================
--- django/contrib/admin/templates/admin/edit_inline/stacked.html	(revision 12873)
+++ django/contrib/admin/templates/admin/edit_inline/stacked.html	(working copy)
@@ -1,5 +1,5 @@
 {% load i18n adminmedia %}
-<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
+<div class="inline-group {% for class in inline_admin_formset.formset.classes %} {{class}}{% endfor %}" id="{{ inline_admin_formset.formset.prefix }}-group">
   <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
 {{ inline_admin_formset.formset.management_form }}
 {{ inline_admin_formset.formset.non_form_errors }}
Index: django/contrib/admin/templates/admin/edit_inline/tabular.html
===================================================================
--- django/contrib/admin/templates/admin/edit_inline/tabular.html	(revision 12873)
+++ 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 12873)
+++ 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=None,
                                   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)
 
