How to display a boolean property in the django admin

后端 未结 5 1373
说谎
说谎 2021-01-31 15:47

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         


        
5条回答
  •  执笔经年
    2021-01-31 16:34

    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']
    

提交回复
热议问题