Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django short description for property

has anyone an idea how to add custom name to property in Django model? For example, if I got property:

@property def my_property(self):      return u'Returns some calculations' 

and I show it in admin as a column:

class MyAdmin(admin.ModelAdmin):     list_display=['my_property',] 

Then I see "My property" column and what I need is "Property X" column. I tried with my_property.short_description and my_property.verbose_name, none of this works.

like image 526
alekwisnia Avatar asked Aug 30 '11 09:08

alekwisnia


1 Answers

The solution by Masatsugu Hosoi works fine, but you can also use the decorator and set short_description on the property getter (fget):

@property def my_property(self):     return u'Returns some calculations' my_property.fget.short_description = u'Property X' 
like image 111
bbrik Avatar answered Sep 23 '22 21:09

bbrik