Show Django Model @property as a bool in model admin
<p>I have a model with a <code>property</code>, It returns boolean, I want to show it as icon in django model admin.</p>

<h2>models.py</h2>

<pre><code>class Foo(models.Model):
    bar = models.TextField("Title", null=True, blank=True)

    @property
    def is_new_bar(self):
        return bar == 'NEW'
</code></pre>

<h2>admin.py</h2>

<pre><code>class FooAdmin(admin.ModelAdmin):
    list_display = ('bar', 'is_new_bar') # is_new_bar is shown as True/False text, I want this as bool icon of django.
</code></pre>

<p><a href="http://i.stack.imgur.com/eoK8x.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/eoK8x.jpg" alt="Boolean Icons"></a></p>

<p>You can add method to your modeladmin that will return property value and set that it will return boolean:</p>

<pre><code>class FooAdmin(admin.ModelAdmin):
     list_display = ('bar', 'get_is_new_bar') 

     def get_is_new_bar(self, obj):
        return self.is_new_bar
     get_is_new_bar.boolean = True
</code></pre>

python django admin