list_display - boolean icons for methods

后端 未结 1 823
無奈伤痛
無奈伤痛 2021-01-30 19:05

When defining the list_display array for a ModelAdmin class, if a BooleanField or NullBooleanField is given the UI will use nice looking i

相关标签:
1条回答
  • 2021-01-30 19:41

    This is documented, although it's a bit hard to find - go a couple of screens down from here, and you'll find this:

    If the string given is a method of the model, ModelAdmin or a callable that returns True or False Django will display a pretty "on" or "off" icon if you give the method a boolean attribute whose value is True.

    and the example given is:

    def born_in_fifties(self):
        return self.birthday.strftime('%Y')[:3] == '195'
    born_in_fifties.boolean = True
    
    0 讨论(0)
提交回复
热议问题