mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #30259 -- Added support for admin_order_field attribute on properties in ModelAdmin.list_display.
This commit is contained in:
committed by
Mariusz Felisiak
parent
ea60b7bc74
commit
044cc54420
@@ -104,7 +104,7 @@ class ArticleAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
'content', 'date', callable_year, 'model_year', 'modeladmin_year',
|
||||
'model_year_reversed', 'section', lambda obj: obj.title,
|
||||
'order_by_expression',
|
||||
'order_by_expression', 'model_property_year',
|
||||
)
|
||||
list_editable = ('section',)
|
||||
list_filter = ('date', 'section')
|
||||
|
||||
@@ -55,6 +55,11 @@ class Article(models.Model):
|
||||
model_year_reversed.admin_order_field = '-date'
|
||||
model_year_reversed.short_description = ''
|
||||
|
||||
def property_year(self):
|
||||
return self.date.year
|
||||
property_year.admin_order_field = 'date'
|
||||
model_property_year = property(property_year)
|
||||
|
||||
|
||||
class Book(models.Model):
|
||||
"""
|
||||
|
||||
@@ -344,6 +344,25 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
||||
"Results of sorting on callable are out of order."
|
||||
)
|
||||
|
||||
def test_change_list_sorting_property(self):
|
||||
"""
|
||||
Sort on a list_display field that is a property (column 10 is
|
||||
a property in Article model).
|
||||
"""
|
||||
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': 10})
|
||||
self.assertContentBefore(
|
||||
response,
|
||||
'Oldest content',
|
||||
'Middle content',
|
||||
'Results of sorting on property are out of order.',
|
||||
)
|
||||
self.assertContentBefore(
|
||||
response,
|
||||
'Middle content',
|
||||
'Newest content',
|
||||
'Results of sorting on property are out of order.',
|
||||
)
|
||||
|
||||
def test_change_list_sorting_callable_query_expression(self):
|
||||
"""
|
||||
Query expressions may be used for admin_order_field. (column 9 is
|
||||
|
||||
Reference in New Issue
Block a user