How to Fix Display Issues in Django Admin Inlines After Upgrading to 5.1
Django
2025-03-13 09:25 (19 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 (No signup or login required)
Currently unrated
Related posts
Return Login and Redirect Views by Hardcoding Social Account Provider in django-allauth (When Using AWS Cognito, etc.)
After Upgrading to Django 5 and Updating Dependencies, SSL: CERTIFICATE_VERIFY_FAILED Error Occurs When Sending Emails
The "first" and "second" Arguments of assertEqual in Django's Unit Tests are Actually "expected" and "actual"
Fix: pipenv install fails with AttributeError: module 'pkgutil' has no attribute 'ImpImporter' (Python 3.12)
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.