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(),
}
...
Comments