summaryrefslogtreecommitdiff
path: root/docs/intro/tutorial07.txt
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2021-01-13 16:19:22 +0000
committerGitHub <noreply@github.com>2021-01-13 17:19:22 +0100
commit920448539631b52dcee53bd32a880abbc9de18bd (patch)
tree03dd52fd206088302de11e0b485b420726718a4a /docs/intro/tutorial07.txt
parent83fcfc9ec8610540948815e127101f1206562ead (diff)
Fixed #16117 -- Added decorators for admin action and display functions.
Refs #25134, #32099.
Diffstat (limited to 'docs/intro/tutorial07.txt')
-rw-r--r--docs/intro/tutorial07.txt16
1 files changed, 10 insertions, 6 deletions
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