From f67fb604ea4cebe2dcc2b3bc8d017bdae546a7a5 Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Fri, 15 Aug 2008 21:57:36 +0000 Subject: [PATCH] Fixed #8341 -- Allow simpler subclassing of ModelAdmin and InlineModelAdmin when overriding get_form and get_formset and needing to pass keyword argument on to the factory functions. Thanks ciantic for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8396 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/options.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index fc7541e37f..408c4add2e 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -334,7 +334,7 @@ class ModelAdmin(BaseModelAdmin): form = self.get_form(request) return [(None, {'fields': form.base_fields.keys()})] - def get_form(self, request, obj=None): + def get_form(self, request, obj=None, **kwargs): """ Returns a Form class for use in the admin add view. This is used by add_view and change_view. @@ -343,7 +343,13 @@ class ModelAdmin(BaseModelAdmin): fields = flatten_fieldsets(self.declared_fieldsets) else: fields = None - return modelform_factory(self.model, form=self.form, fields=fields, formfield_callback=self.formfield_for_dbfield) + defaults = { + "form": self.form, + "fields": fields, + "formfield_callback": self.formfield_for_dbfield, + } + defaults.update(kwargs) + return modelform_factory(self.model, **defaults) def get_formsets(self, request, obj=None): for inline in self.inline_instances: @@ -833,16 +839,23 @@ class InlineModelAdmin(BaseModelAdmin): return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js]) media = property(_media) - def get_formset(self, request, obj=None): + def get_formset(self, request, obj=None, **kwargs): """Returns a BaseInlineFormSet class for use in admin add/change views.""" if self.declared_fieldsets: fields = flatten_fieldsets(self.declared_fieldsets) else: fields = None - return inlineformset_factory(self.parent_model, self.model, - form=self.form, formset=self.formset, fk_name=self.fk_name, - fields=fields, formfield_callback=self.formfield_for_dbfield, - extra=self.extra, max_num=self.max_num) + defaults = { + "form": self.form, + "formset": self.formset, + "fk_name": self.fk_name, + "fields": fields, + "formfield_callback": self.formfield_for_dbfield, + "extra": self.extra, + "max_num": self.max_num, + } + defaults.update(kwargs) + return inlineformset_factory(self.parent_model, self.model, **defaults) def get_fieldsets(self, request, obj=None): if self.declared_fieldsets: