mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #24908 -- Fixed duplicate readonly field rendering.
ModelAdmin added readonly_fields to exclude, but would not undeclare them if they were overridden.
This commit is contained in:
parent
60f795c060
commit
fedef7b2c6
2 changed files with 42 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue