Reputation: 21
I have a Django Boolean Field which is shown with pretty 'on' 'off' buttons in the list display (green and red). Is it possible to have a third state like yellow or blue, indicating state is unknown.
PS : I have read about NullBooleanField, but that doesn't change my widget. All I need is, Django to display a third color based on a third value for my boolean field.
Upvotes: 1
Views: 1012
Reputation:
The rules for this are buried pretty deep in the Django admin app.
def _boolean_icon(field_val):
icon_url = static('admin/img/icon-%s.gif' %
{True: 'yes', False: 'no', None: 'unknown'}[field_val])
return format_html('<img src="{}" alt="{}" />', icon_url, field_val)
This is then called in admin/utils.py
, so changing it to support multiple values may be tricky.
Fortunately, it does handle the NullBooleanField
and there is an image for "unknown values" shown below:
icon-unknown.gif
icon-yes.gif
icon-no.gif
Upvotes: 3