Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #8341 -- Allow simpler subclassing of ModelAdmin and InlineMode…

…lAdmin 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
  • Loading branch information...
commit f67fb604ea4cebe2dcc2b3bc8d017bdae546a7a5 1 parent 8edb4f9
Brian Rosner brosner authored
Showing with 20 additions and 7 deletions.
  1. +20 −7 django/contrib/admin/options.py
27 django/contrib/admin/options.py
View
@@ -334,7 +334,7 @@ def get_fieldsets(self, request, obj=None):
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 @@ def get_form(self, request, obj=None):
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 @@ def _media(self):
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:
Please sign in to comment.
Something went wrong with that request. Please try again.