Ticket #15820: 15820.inlinemodeladmin-get_fieldsets.diff
File 15820.inlinemodeladmin-get_fieldsets.diff, 2.4 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index c603210..ef600de 100644
a b class InlineModelAdmin(BaseModelAdmin): 1350 1350 def get_fieldsets(self, request, obj=None): 1351 1351 if self.declared_fieldsets: 1352 1352 return self.declared_fieldsets 1353 form = self.get_formset(request ).form1353 form = self.get_formset(request, obj).form 1354 1354 fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj)) 1355 1355 return [(None, {'fields': fields})] 1356 1356 -
tests/regressiontests/modeladmin/tests.py
diff --git a/tests/regressiontests/modeladmin/tests.py b/tests/regressiontests/modeladmin/tests.py index 530b476..3faf18c 100644
a b class ModelAdminTests(TestCase): 180 180 '<option value="%d">The Doors</option>\n' 181 181 '</select>' % self.band.id) 182 182 183 def test_regression_for_ticket_15820(self): 184 """ 185 Ensure that `obj` is passed from `InlineModelAdmin.get_fieldsets()` to 186 `InlineModelAdmin.get_formset()`. 187 """ 188 class CustomConcertForm(forms.ModelForm): 189 190 class Meta: 191 model = Concert 192 fields = ['day'] 193 194 class ConcertInline(TabularInline): 195 model = Concert 196 fk_name = 'main_band' 197 198 def get_formset(self, request, obj=None, **kwargs): 199 if obj: 200 kwargs['form'] = CustomConcertForm 201 return super(ConcertInline, self).get_formset(request, obj, **kwargs) 202 203 class BandAdmin(ModelAdmin): 204 inlines = [ 205 ConcertInline 206 ] 207 208 concert = Concert.objects.create(main_band=self.band, opening_band=self.band, day=1) 209 ma = BandAdmin(Band, self.site) 210 fieldsets = list(ma.inline_instances[0].get_fieldsets(request)) 211 self.assertEqual(fieldsets[0][1]['fields'], ['main_band', 'opening_band', 'day', 'transport']) 212 fieldsets = list(ma.inline_instances[0].get_fieldsets(request, ma.inline_instances[0].model)) 213 self.assertEqual(fieldsets[0][1]['fields'], ['day']) 214 183 215 # radio_fields behavior ########################################### 184 216 185 217 def test_default_foreign_key_widget(self):