How to Fix Display Issues in Django Admin Inlines After Upgrading to 5.1
Django
2025-03-13 09:25 (12 months ago)
This issue may occur only when using Grappelli.
From around Django 5, a key called is_hidden was added to the instance variable field of django.contrib.admin.helpers.AdminReadonlyField.
This key becomes True when the widget of an AdminForm is something like HiddenInput. (Refer to the code)
Moreover, if _meta.widgets['field_name'] does not exist in the Form, the widget becomes HiddenInput. (Refer to the code)
Therefore, by defining Meta in the Admin form class and specifying something like TextInput in the widgets, you can display the widget instead of a strange str(dict) representation.
class MyInlineAdminForm(forms.ModelForm):
class Meta:
# Added from Django 5. Without this, the value would be displayed as str(dict), which looks strange.
# Specified as TextInput, but since it is ReadOnly, the ID will just be a string.
widgets = {
'id': forms.TextInput(),
}
...
Please rate this article
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.