Displaying properties in Django admin - translating their names
In my Django application my model has some values set as properties - they are calculated on demand from other values (like, min. value of some other objects' field, etc). This works pretty well as I don't need to store those in the database and the calculations can be expensive, so they're cached.
So I have a model:
class A(models.Model):
name = models.TextField(_('Name'))
def max_of_some_values(self):
# calculate it here, with caching,etc
return 1
max_value = property(max_of_some_values)
When I show this in my admin application, on the object list the name
column is displaying using it's translation. So in Polish it's Nazwa
, English it's Name
, etc.
At the same time I开发者_如何学运维 found no way of adding a translated 'column' name for my property.
Anyone handled this before?
You can set a short_description
property on the method to determine the column name - I believe it should be possible to mark this as translatable.
def max_of_some_values(self):
# calculate it here, with caching,etc
return 1
max_of_some_values.short_description = _('Max value')
精彩评论