As we all know, displaying a method return value as boolean in the Django admin is easily done by setting the boolean
attribute:
class MyMo
You need to create a shadowing
function to the property in the model. What I mean is that you will need to recreate a function in the ModelAdmin class with the same name as the property defined in the main Model.
Example:
# Model
class Product(models.Model):
@property # you can omit this decorator if you will access this property as a method of the model instance
def in_stock(self):
# boolean check return
return self.quantity > 0
...
# Django-modeladmin
class ProductAdmin(admin.ModelAdmin):
list_display = ('in_stock', ...)
def in_stock(self, instance):
return instance.in_stock
in_stock.boolean = True