Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15820 -- Fixed the use of the InlineAdmin's get_formset method…

… by actually passing in the obj. Thanks, Julien Phalip.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16497 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f9fe112f2d65ea187ad47b280197664b551f339e 1 parent 43cb78f
@jezdez jezdez authored
View
2  django/contrib/admin/options.py
@@ -1360,7 +1360,7 @@ def get_formset(self, request, obj=None, **kwargs):
def get_fieldsets(self, request, obj=None):
if self.declared_fieldsets:
return self.declared_fieldsets
- form = self.get_formset(request).form
+ form = self.get_formset(request, obj).form
fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj))
return [(None, {'fields': fields})]
View
32 tests/regressiontests/modeladmin/tests.py
@@ -237,6 +237,38 @@ class ConcertAdmin(ModelAdmin):
'<option value="%d">The Doors</option>\n'
'</select>' % self.band.id)
+ def test_regression_for_ticket_15820(self):
+ """
+ Ensure that `obj` is passed from `InlineModelAdmin.get_fieldsets()` to
+ `InlineModelAdmin.get_formset()`.
+ """
+ class CustomConcertForm(forms.ModelForm):
+
+ class Meta:
+ model = Concert
+ fields = ['day']
+
+ class ConcertInline(TabularInline):
+ model = Concert
+ fk_name = 'main_band'
+
+ def get_formset(self, request, obj=None, **kwargs):
+ if obj:
+ kwargs['form'] = CustomConcertForm
+ return super(ConcertInline, self).get_formset(request, obj, **kwargs)
+
+ class BandAdmin(ModelAdmin):
+ inlines = [
+ ConcertInline
+ ]
+
+ concert = Concert.objects.create(main_band=self.band, opening_band=self.band, day=1)
+ ma = BandAdmin(Band, self.site)
+ fieldsets = list(ma.inline_instances[0].get_fieldsets(request))
+ self.assertEqual(fieldsets[0][1]['fields'], ['main_band', 'opening_band', 'day', 'transport'])
+ fieldsets = list(ma.inline_instances[0].get_fieldsets(request, ma.inline_instances[0].model))
+ self.assertEqual(fieldsets[0][1]['fields'], ['day'])
+
# radio_fields behavior ###########################################
def test_default_foreign_key_widget(self):
Please sign in to comment.
Something went wrong with that request. Please try again.