From 920448539631b52dcee53bd32a880abbc9de18bd Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Wed, 13 Jan 2021 16:19:22 +0000 Subject: Fixed #16117 -- Added decorators for admin action and display functions. Refs #25134, #32099. --- docs/intro/tutorial07.txt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'docs/intro/tutorial07.txt') diff --git a/docs/intro/tutorial07.txt b/docs/intro/tutorial07.txt index 9bcc2b40a3..545e40baa3 100644 --- a/docs/intro/tutorial07.txt +++ b/docs/intro/tutorial07.txt @@ -228,22 +228,26 @@ of an arbitrary method is not supported. Also note that the column header for underscores replaced with spaces), and that each line contains the string representation of the output. -You can improve that by giving that method (in :file:`polls/models.py`) a few -attributes, as follows: +You can improve that by using the :func:`~django.contrib.admin.display` +decorator on that method (in :file:`polls/models.py`), as follows: .. code-block:: python :caption: polls/models.py + from django.contrib import admin + class Question(models.Model): # ... + @admin.display( + boolean=True, + ordering='pub_date', + description='Published recently?', + ) def was_published_recently(self): now = timezone.now() return now - datetime.timedelta(days=1) <= self.pub_date <= now - was_published_recently.admin_order_field = 'pub_date' - was_published_recently.boolean = True - was_published_recently.short_description = 'Published recently?' -For more information on these method properties, see +For more information on the properties configurable via the decorator, see :attr:`~django.contrib.admin.ModelAdmin.list_display`. Edit your :file:`polls/admin.py` file again and add an improvement to the -- cgit v1.3