How do I invert in Django the pretty "yes", "no" icons of a BooleanField in the Admin site?

Question:

When your model has a BooleanField, the Django Admin site displays circular icons:

  • a green checkmark for "True"
  • a red X for "False"

The Django docs call those icons "pretty":

If the field is a BooleanField, Django will display a pretty “yes”,
“no”, or “unknown” icon instead of True, False, or None.

it looks great! but my BooleanField is called "pending" so if pending = True , I want Django Admin site to display a red X instead of a green checkmark. Because green means "good" and red means "bad". Most of my entries are not pending, so the list is full of red X icons, it looks bad, I want them to be mostly green checkmarks instead.

I know I could add a def in the model with a return not self.pending but that displays the words "True" and "False" instead, I want the icons.

Asked By: Phil Rv

||

Answers:

You can set boolean=True when define custom admin field like this

@admin.register(YourModel)
class YourAdmin(admin.ModelAdmin):
    list_display = ('pk', 'is_not_pending')

    @admin.display(description='Is not pending', boolean=True)
    def is_not_pending(self, obj):
        return not obj.pending
Answered By: Jayce