mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #31558 -- Added support for boolean attribute on properties in ModelAdmin.list_display.
This commit is contained in:
committed by
Mariusz Felisiak
parent
2f1ab16be5
commit
225328efd9
@@ -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")
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user