My own method used in list_display and value as boolean icon

django, django-admin, python

Solution

Change your code to the following:

class MyClassAdmin(admin.ModelAdmin):

    list_display = ('my_own_method')

    def my_own_method(self, obj):
        if [condition]:       
            return True
        else: 
            return False
    my_own_method.boolean = True

which can be found in the documentation on `list_display`:

If the string given is a method of the model, ModelAdmin or a callable that returns True or False Django will display a pretty "on" or "off" icon if you give the method a boolean attribute whose value is True.

Problem

I wrote my own method used in list_display (admin class), like this: ``` class MyClassAdmin(admin.ModelAdmin): list_display = ('my_own_method') def my_own_method(self, obj): if [condition]: return True else: return False ``` but this value is displayed on list as text (True or False), not as default django boolean icons like this: What should I do to change this?

Original source