小编not*_*ess的帖子

在模型管理中将Django Model @property显示为bool

我有一个带有的模型property,它返回布尔值,我想在Django模型管理中将其显示为图标。

models.py

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

    @property
    def is_new_bar(self):
        return bar == 'NEW'
Run Code Online (Sandbox Code Playgroud)

管理员

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.
Run Code Online (Sandbox Code Playgroud)

布尔图标

python django admin

1
推荐指数
1
解决办法
863
查看次数

标签 统计

admin ×1

django ×1

python ×1