mirror of
https://github.com/django/django.git
synced 2024-12-24 18:16:19 +00:00
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:
parent
8edb4f97c7
commit
f67fb604ea
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user