Skip to content

openwisp/django-readonly-issue-demo-30577

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Admin readonly custom widget - Ticket #30577

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.

What This Project Demonstrates

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.

Testing Instructions

Step 1: Test with Django 5.2 (Working Behavior)

  1. Ensure Django 5.2 is installed:

    pip install Django==5.2.4
  2. Run the project:

    python manage.py migrate
    python manage.py runserver
  3. Test the staffuser experience:

Custom widget used for rendering readonly field

Step 2: Test with Django Main Branch (Broken Behavior)

  1. Install Django from main branch:

    pip install git+https://github.com/django/django.git
  2. Run the same project:

    python manage.py runserver
  3. 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)

Django 6.0 uses default rendering instead of custom widget

Key Difference

  • Django 5.2: Custom ReadOnlyIndentedJSONWidget is used → JSON displayed with proper formatting
  • Django Main: Custom widget ignored → Default readonly rendering used → Poor user experience

About

PoC for Django Ticket 30577

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages