diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 1f8ff6d..c1a8450 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
352 | 352 | exclude = [] |
353 | 353 | else: |
354 | 354 | exclude = list(self.exclude) |
355 | | exclude.extend(kwargs.get("exclude", [])) |
356 | 355 | exclude.extend(self.get_readonly_fields(request, obj)) |
357 | 356 | # if exclude is an empty list we pass None to be consistant with the |
358 | 357 | # default on modelform_factory |
… |
… |
class InlineModelAdmin(BaseModelAdmin):
|
1244 | 1243 | exclude = [] |
1245 | 1244 | else: |
1246 | 1245 | exclude = list(self.exclude) |
1247 | | exclude.extend(kwargs.get("exclude", [])) |
1248 | 1246 | exclude.extend(self.get_readonly_fields(request, obj)) |
1249 | 1247 | # if exclude is an empty list we use None, since that's the actual |
1250 | 1248 | # default |
diff --git a/tests/regressiontests/modeladmin/models.py b/tests/regressiontests/modeladmin/models.py
index 36ea416..0133f35 100644
a
|
b
|
displayed because you forgot to add it to fields/fielsets
|
141 | 141 | >>> ma.get_form(request).base_fields.keys() |
142 | 142 | ['name'] |
143 | 143 | |
| 144 | # Passing `exclude` to get_form as a keyword argument will override the |
| 145 | # value generated by the method, disregarding the `exclude` and |
| 146 | # `readonly_fields` attributes on the ModelAdmin instance. |
| 147 | |
| 148 | >>> class BandAdmin(ModelAdmin): |
| 149 | ... fields = ['name', 'bio', 'sign_date'] |
| 150 | ... exclude = ['bio'] |
| 151 | ... readonly_fields = ['sign_date'] |
| 152 | >>> ma = BandAdmin(Band, site) |
| 153 | >>> ma.get_form(request, exclude=['name']).base_fields.keys() |
| 154 | ['bio', 'sign_date'] |
| 155 | |
144 | 156 | If we specify a form, it should use it allowing custom validation to work |
145 | 157 | properly. This won't, however, break any of the admin widgets or media. |
146 | 158 | |
… |
… |
blank=True for the model field. Finally, the widget should have the
|
302 | 314 | >>> list(ma.get_formsets(request))[0]().forms[0].fields.keys() |
303 | 315 | ['extra', 'transport', 'id', 'DELETE', 'main_band'] |
304 | 316 | |
| 317 | # Using `exclude` on InlineModelAdmin.get_formset |
| 318 | >>> ma.inline_instances[0].get_formset(request, exclude=['transport']).form.base_fields.keys() |
| 319 | ['extra', 'main_band'] |
| 320 | |
305 | 321 | |
306 | 322 | >>> band.delete() |
307 | 323 | |