As we all know, displaying a method return value as boolean in the Django admin is easily done by setting the boolean attribute:
class MyModel(models.Model):
def is_something(self):
if self.something == 'something':
return True
return False
is_something.boolean = True
How can you achieve the same effect for a property, like in the following case?
class MyModel(models.Model):
@property
def is_something(self):
if self.something == 'something':
return True
return False
Waiting for better solutions to come up, I’ve solved it in the following way:
I’ll then reference the
_is_somethingmethod in theModelAdminsubclass:And the
is_somethingproperty otherwise: