List_display - boolean icons for methods

When defining the list_display array for the ModelAdmin class, if BooleanField or NullBooleanField , the user interface will use nice icons instead of True / False text in the column. However, if a method is given that returns a boolean, it simply outputs True / False.

Can I use cute icons for a boolean method?

+82
django django-admin
Nov 22 '11 at 12:43
source share
1 answer

This is documented, although it is a little hard to find - go to a couple of screens from here and you will find the following:

If the given string is a model method, ModelAdmin, or a callable that returns True or False Django, displays a nice "on" or "off" badge if you give a a boolean method to an attribute whose value is True .

and the given example:

 def born_in_fifties(self): return self.birthday.strftime('%Y')[:3] == '195' born_in_fifties.boolean = True 
+153
Nov 22 '11 at 12:47
source share



All Articles