This project demonstrates a breaking change in Django's main branch related to rendering of widgets in Django admin with read_only attribute.
In Django ticket #30577 for custom rendering of readonly fields in Django admin, it was suggested to set read_only = True
on the widget. This utilized the workaround present for ReadOnlyPasswordHashWidget
to force Django to use custom widget for rendering the readonly field.
In PR #19063, this workaround for the ReadOnlyPasswordHashWidget
was removed, breaking the rendering of readonly fields.
This project shows the difference in behavior between:
- Django 5.2: Custom widgets work correctly for view-only users
- Django main branch: Custom widgets are ignored, falling back to default rendering
Note
The project includes SQLite database which contains required objects for demonstration.
The focus is on the staffuser
who has view-only permissions for the JsonDataModel.
-
Ensure Django 5.2 is installed:
pip install Django==5.2.4
-
Run the project:
python manage.py migrate python manage.py runserver
-
Test the staffuser experience:
- Visit: http://127.0.0.1:8000/admin/jsonapp/jsondatamodel/3/change/
- Login with:
staffuser
/Django@123
- Expected Result: JSON is displayed with proper indentation in a disabled textarea using the custom
ReadOnlyIndentedJSONWidget
-
Install Django from main branch:
pip install git+https://github.com/django/django.git
-
Run the same project:
python manage.py runserver
-
Test the staffuser experience again:
- Login with:
staffuser
/Django@123
- Navigate to "JSON Data" and open any object
- Actual Result: Custom widget is ignored, JSON is displayed using default readonly rendering (likely as plain text without formatting)
- Login with:
- Django 5.2: Custom
ReadOnlyIndentedJSONWidget
is used → JSON displayed with proper formatting - Django Main: Custom widget ignored → Default readonly rendering used → Poor user experience