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
This commit is contained in:
Brian Rosner 2008-08-15 21:57:36 +00:00
parent 8edb4f97c7
commit f67fb604ea
1 changed files with 20 additions and 7 deletions

View File

@ -334,7 +334,7 @@ class ModelAdmin(BaseModelAdmin):
form = self.get_form(request) form = self.get_form(request)
return [(None, {'fields': form.base_fields.keys()})] 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 Returns a Form class for use in the admin add view. This is used by
add_view and change_view. add_view and change_view.
@ -343,7 +343,13 @@ class ModelAdmin(BaseModelAdmin):
fields = flatten_fieldsets(self.declared_fieldsets) fields = flatten_fieldsets(self.declared_fieldsets)
else: else:
fields = None 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): def get_formsets(self, request, obj=None):
for inline in self.inline_instances: 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]) return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
media = property(_media) 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.""" """Returns a BaseInlineFormSet class for use in admin add/change views."""
if self.declared_fieldsets: if self.declared_fieldsets:
fields = flatten_fieldsets(self.declared_fieldsets) fields = flatten_fieldsets(self.declared_fieldsets)
else: else:
fields = None fields = None
return inlineformset_factory(self.parent_model, self.model, defaults = {
form=self.form, formset=self.formset, fk_name=self.fk_name, "form": self.form,
fields=fields, formfield_callback=self.formfield_for_dbfield, "formset": self.formset,
extra=self.extra, max_num=self.max_num) "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): def get_fieldsets(self, request, obj=None):
if self.declared_fieldsets: if self.declared_fieldsets: