0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Fixed #9588 -- Allow passing kwargs to GenericInlineModelAdmin.get_formset just like the InlineModelAdmin. Thanks, prestontimmons.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16419 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-06-16 16:35:04 +00:00
parent 97f22f2969
commit 30e842632e
2 changed files with 20 additions and 3 deletions

View File

@ -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 @@ class GenericInlineModelAdmin(InlineModelAdmin):
"max_num": self.max_num,
"exclude": exclude
}
defaults.update(kwargs)
return generic_inlineformset_factory(self.model, **defaults)
class GenericStackedInline(GenericInlineModelAdmin):

View File

@ -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 @@ class NoInlineDeletionTest(TestCase):
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)