diff options
| author | Ryanwalker277 <andianurag277@gmail.com> | 2023-09-14 17:40:20 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-16 20:54:26 +0200 |
| commit | 225328efd9814f2e922ee77fb48a3eea7428c397 (patch) | |
| tree | faa3793b275ea6a3e83120ae3648d790c3c856f7 /tests/admin_views | |
| parent | 2f1ab16be54255213d5c3e4d925a3a24997dc917 (diff) | |
Fixed #31558 -- Added support for boolean attribute on properties in ModelAdmin.list_display.
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/admin.py | 1 | ||||
| -rw-r--r-- | tests/admin_views/models.py | 6 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 8 |
3 files changed, 15 insertions, 0 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 389e1e8370..c157e70505 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -216,6 +216,7 @@ class ArticleAdmin(ArticleAdminWithExtraUrl): "model_month", "order_by_f_expression", "order_by_orderby_expression", + "model_property_is_from_past", ) list_editable = ("section",) list_filter = ("date", "section") diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py index de16796e85..67d3ec4c86 100644 --- a/tests/admin_views/models.py +++ b/tests/admin_views/models.py @@ -9,6 +9,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.core.files.storage import FileSystemStorage from django.db import models +from django.utils import timezone class Section(models.Model): @@ -66,6 +67,11 @@ class Article(models.Model): def model_month(self): return self.date.month + @property + @admin.display(description="Is from past?", boolean=True) + def model_property_is_from_past(self): + return self.date < timezone.now() + class Book(models.Model): """ diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 164de1d01c..4ea261b347 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -486,6 +486,14 @@ class AdminViewBasicTest(AdminViewBasicTestCase): "Results of sorting on callable are out of order.", ) + def test_change_list_boolean_display_property(self): + response = self.client.get(reverse("admin:admin_views_article_changelist")) + self.assertContains( + response, + '<td class="field-model_property_is_from_past">' + '<img src="/static/admin/img/icon-yes.svg" alt="True"></td>', + ) + def test_change_list_sorting_property(self): """ Sort on a list_display field that is a property (column 10 is |
