How to Fix Display Issues in Django Admin Inlines After Upgrading to 5.1

Django
2025-03-13 18:25 (4 weeks ago) ytyng

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

    ...
Current rating: 1
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Comments

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011