Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django admin list_display invert (not) a boolean field

Tags:

django-admin

I have:

class MyModelAdmin(admin.ModelAdmin):
    list_display = ('name', 'locked', )

It displays the nice green and red icons for the locked field.

What I want is to show inverted values in locked field.

So i wrote this:

def not_locked(obj):
    return not obj.locked
class MyModelAdmin(admin.ModelAdmin):
    list_display = ('name', not_locked,)

And this works (inverts the values), but it displays ugly True or False instead of the nice green and red icons.

How to make it show the icons again?

like image 377
frnhr Avatar asked Oct 05 '10 21:10

frnhr


1 Answers

just add to your method 'not_locked' attribute boolean=True,

def not_locked(self, obj):
    return not obj.locked
not_locked.boolean = True
like image 199
partizan Avatar answered Sep 22 '22 03:09

partizan