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?
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.
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