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?
just add to your method 'not_locked' attribute boolean=True,
def not_locked(self, obj):
return not obj.locked
not_locked.boolean = True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With