When using list_display as described under http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display you can not only display fields but custom callables as well:
def colored_name(self):
return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
colored_name.allow_tags = True
And then use it like this:
list_display = ('first_name', 'last_name', 'colored_name')
Since first_name and last_name are normal fields we can just translate them like that:
first_name = models.CharField(_('first name'))
last_name = models.CharField(_('last name'))
So the question is:
How can I translate the name of my function? Where do I put my _('colored name')?
Use the function django. utils. translation. gettext_noop() to mark a string as a translation string without translating it.
The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.
your company should follow a least access principle policy; so yes: only select people should have access. Django has basic auditing capability via signals and displayed in the admin out of the box. You can build on top of this.
The example on the page that you linked to shows that the callable can have an attribute short_description
, which is the string used as the title of the column. I haven't checked, but I strongly suspect that if you set that to a translatable string then it will work.
def colored_name(self):
return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
colored_name.allow_tags = True
colored_name.short_description = _("Colored Name")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With