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
this is the simplest way I found, directly in the ModelAdmin:
class MyModelAdmin(admin.ModelAdmin): def is_something(self, instance): return instance.something == "something" is_something.boolean = True is_something.short_description = u"Is something" list_display = ['is_something']
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