#36926: Admin list_display does not use boolean icons when traversing properties
--------------------------------+--------------------------------------
     Reporter:  Michael Nagler  |                    Owner:  Huwaiza
         Type:  New feature     |                   Status:  assigned
    Component:  contrib.admin   |                  Version:  6.0
     Severity:  Normal          |               Resolution:
     Keywords:                  |             Triage Stage:  Unreviewed
    Has patch:  1               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  1
--------------------------------+--------------------------------------
Comment (by Huwaiza):

 Yes, that is exactly right. When a field is a direct BooleanField on the
 model for example
 {{{
 list_display = ['is_active']
 }}}
 Django already automatically displays it as a boolean icon, no
 @admin.display(boolean=True) needed.

 This is handled in display_for_field() in django/contrib/admin/utils.py:

 {{{
 elif isinstance(field, models.BooleanField):
      return _boolean_icon(value)
 }}}


 The bug is specifically about **related field traversal**. When you write
 'profile__verified' instead of 'verified', Django cannot find the field
 via _get_non_gfk_field() because the name contains '__', so it falls back
 to f=None. With f=None, it calls display_for_value() instead of
 display_for_field(), which simply returns str(value) → "True"/"False".

 This fix closes that gap: when traversing a relation path with '__', we
 resolve the final field using get_fields_from_path() and pass it as f, so
 display_for_field() is called correctly and the same automatic boolean
 icon behavior that exists for direct fields is preserved.

 Regarding your question about plain text being useful, No, there is no
 case where a BooleanField should display as plain text in the changelist.
 Django already makes this decision unconditionally for direct
 BooleanFields, the fix simply extends that same existing behavior to
 related field traversal for consistency.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36926#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019c7225b334-7558c629-d9e7-449a-a95f-effd4b67af1e-000000%40eu-central-1.amazonses.com.

Reply via email to