diff options
| author | jpic <jamespic@gmail.com> | 2015-06-06 03:29:07 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-07-02 13:37:30 -0400 |
| commit | fedef7b2c6e80e1e58b028cf9c03267a8950bf6f (patch) | |
| tree | b5e9e7841e422227e61bd0576172e16a46be9205 /tests | |
| parent | 60f795c0608119cdb02d61d3eb59f34ebdb55754 (diff) | |
Fixed #24908 -- Fixed duplicate readonly field rendering.
ModelAdmin added readonly_fields to exclude, but would not undeclare
them if they were overridden.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeladmin/tests.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 14ac030ec9..918daffe3e 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -221,6 +221,37 @@ class ModelAdminTests(TestCase): list(list(ma.get_formsets_with_inlines(request))[0][0]().forms[0].fields), ['main_band', 'opening_band', 'id', 'DELETE']) + def test_custom_formfield_override_readonly(self): + class AdminBandForm(forms.ModelForm): + name = forms.CharField() + + class Meta: + exclude = tuple() + model = Band + + class BandAdmin(ModelAdmin): + form = AdminBandForm + readonly_fields = ['name'] + + ma = BandAdmin(Band, self.site) + + # `name` shouldn't appear in base_fields because it's part of + # readonly_fields. + self.assertEqual( + list(ma.get_form(request).base_fields), + ['bio', 'sign_date'] + ) + # But it should appear in get_fields()/fieldsets() so it can be + # displayed as read-only. + self.assertEqual( + list(ma.get_fields(request)), + ['bio', 'sign_date', 'name'] + ) + self.assertEqual( + list(ma.get_fieldsets(request)), + [(None, {'fields': ['bio', 'sign_date', 'name']})] + ) + def test_custom_form_meta_exclude(self): """ Ensure that the custom ModelForm's `Meta.exclude` is overridden if |
