Fixed #16117 -- Added decorators for admin action and display functions.

Refs #25134, #32099.
This commit is contained in:
Nick Pope 2021-01-13 16:19:22 +00:00 committed by GitHub
parent 83fcfc9ec8
commit 9204485396
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 422 additions and 148 deletions

View file

@ -389,12 +389,14 @@ verbose names Django performs by looking at the model's class name::
verbose_name = _('my thing')
verbose_name_plural = _('my things')
Model methods ``short_description`` attribute values
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Model methods ``description`` argument to the ``@display`` decorator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For model methods, you can provide translations to Django and the admin site
with the ``short_description`` attribute::
with the ``description`` argument to the :func:`~django.contrib.admin.display`
decorator::
from django.contrib import admin
from django.db import models
from django.utils.translation import gettext_lazy as _
@ -406,9 +408,9 @@ with the ``short_description`` attribute::
verbose_name=_('kind'),
)
@admin.display(description=_('Is it a mouse?'))
def is_mouse(self):
return self.kind.type == MOUSE_TYPE
is_mouse.short_description = _('Is it a mouse?')
Working with lazy translation objects
-------------------------------------