Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18681 -- GenericInlineModelAdmin.get_formset() no longer bypas…

…ses get_fieldsets().

Refs 23e1b59 which already fixed this issue for ModelAdmin and InlineModelAdmin.
  • Loading branch information...
commit a0ed2f9260f995b0cdf145f2802fc8123c25db65 1 parent 920b242
Loic Bistuer authored July 31, 2013 timgraham committed August 02, 2013
6  django/contrib/contenttypes/generic.py
@@ -465,10 +465,10 @@ class GenericInlineModelAdmin(InlineModelAdmin):
465 465
     formset = BaseGenericInlineFormSet
466 466
 
467 467
     def get_formset(self, request, obj=None, **kwargs):
468  
-        if self.declared_fieldsets:
469  
-            fields = flatten_fieldsets(self.declared_fieldsets)
  468
+        if 'fields' in kwargs:
  469
+            fields = kwargs.pop('fields')
470 470
         else:
471  
-            fields = None
  471
+            fields = flatten_fieldsets(self.get_fieldsets(request, obj))
472 472
         if self.exclude is None:
473 473
             exclude = []
474 474
         else:
20  tests/generic_inline_admin/tests.py
@@ -325,3 +325,23 @@ class EpisodeAdmin(admin.ModelAdmin):
325 325
         self.assertEqual(
326 326
             list(list(ma.get_formsets(request))[0]().forms[0].fields),
327 327
             ['description', 'keywords', 'id', 'DELETE'])
  328
+
  329
+    def test_get_fieldsets(self):
  330
+        # Test that get_fieldsets is called when figuring out form fields.
  331
+        # Refs #18681.
  332
+        class MediaForm(ModelForm):
  333
+            class Meta:
  334
+                model = Media
  335
+                fields = '__all__'
  336
+
  337
+        class MediaInline(GenericTabularInline):
  338
+            form = MediaForm
  339
+            model = Media
  340
+            can_delete = False
  341
+
  342
+            def get_fieldsets(self, request, obj=None):
  343
+                return [(None, {'fields': ['url', 'description']})]
  344
+
  345
+        ma = MediaInline(Media, self.site)
  346
+        form = ma.get_formset(None).form
  347
+        self.assertEqual(form._meta.fields, ['url', 'description'])

0 notes on commit a0ed2f9

Please sign in to comment.
Something went wrong with that request. Please try again.