Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #9588 -- Allow passing kwargs to `GenericInlineModelAdmin.get_f…

…ormset` just like the InlineModelAdmin. Thanks, prestontimmons.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16419 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 30e842632e6ed95828241fb62f50eb1da9e4019c 1 parent 97f22f2
@jezdez jezdez authored
View
3  django/contrib/contenttypes/generic.py
@@ -396,7 +396,7 @@ class GenericInlineModelAdmin(InlineModelAdmin):
ct_fk_field = "object_id"
formset = BaseGenericInlineFormSet
- def get_formset(self, request, obj=None):
+ def get_formset(self, request, obj=None, **kwargs):
if self.declared_fieldsets:
fields = flatten_fieldsets(self.declared_fieldsets)
else:
@@ -420,6 +420,7 @@ def get_formset(self, request, obj=None):
"max_num": self.max_num,
"exclude": exclude
}
+ defaults.update(kwargs)
return generic_inlineformset_factory(self.model, **defaults)
class GenericStackedInline(GenericInlineModelAdmin):
View
20 tests/regressiontests/generic_inline_admin/tests.py
@@ -1,12 +1,13 @@
# coding: utf-8
from django.conf import settings
+from django.contrib.admin.sites import AdminSite
from django.contrib.contenttypes.generic import generic_inlineformset_factory
from django.test import TestCase
# local test models
-from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \
- Media, EpisodePermanent, MediaPermanentInline, Category
+from models import (Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude,
+ Media, MediaInline, EpisodePermanent, MediaPermanentInline, Category)
class GenericAdminViewTest(TestCase):
@@ -214,3 +215,18 @@ def test_no_deletion(self):
fake_request = object()
formset = inline.get_formset(fake_request)
self.assertFalse(formset.can_delete)
+
+class GenericInlineModelAdminTest(TestCase):
+
+ def test_get_formset_kwargs(self):
+ media_inline = MediaInline(Media, AdminSite())
+
+ # Create a formset with default arguments
+ formset = media_inline.get_formset(None)
+ self.assertEqual(formset.max_num, None)
+ self.assertEqual(formset.can_order, False)
+
+ # Create a formset with custom keyword arguments
+ formset = media_inline.get_formset(None, max_num=100, can_order=True)
+ self.assertEqual(formset.max_num, 100)
+ self.assertEqual(formset.can_order, True)
Please sign in to comment.
Something went wrong with that request. Please try again.