mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #30981 -- Fixed admin changelist crash when using F() or OrderBy() expressions in admin_order_field.
This commit is contained in:
committed by
Mariusz Felisiak
parent
e9def97d10
commit
0284a26af9
@@ -364,30 +364,47 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
||||
)
|
||||
|
||||
def test_change_list_sorting_callable_query_expression(self):
|
||||
"""
|
||||
Query expressions may be used for admin_order_field. (column 9 is
|
||||
order_by_expression in ArticleAdmin).
|
||||
"""
|
||||
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '9'})
|
||||
self.assertContentBefore(
|
||||
response, 'Oldest content', 'Middle content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
self.assertContentBefore(
|
||||
response, 'Middle content', 'Newest content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
"""Query expressions may be used for admin_order_field."""
|
||||
tests = [
|
||||
('order_by_expression', 9),
|
||||
('order_by_f_expression', 12),
|
||||
('order_by_orderby_expression', 13),
|
||||
]
|
||||
for admin_order_field, index in tests:
|
||||
with self.subTest(admin_order_field):
|
||||
response = self.client.get(
|
||||
reverse('admin:admin_views_article_changelist'),
|
||||
{'o': index},
|
||||
)
|
||||
self.assertContentBefore(
|
||||
response, 'Oldest content', 'Middle content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
self.assertContentBefore(
|
||||
response, 'Middle content', 'Newest content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
|
||||
def test_change_list_sorting_callable_query_expression_reverse(self):
|
||||
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '-9'})
|
||||
self.assertContentBefore(
|
||||
response, 'Middle content', 'Oldest content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
self.assertContentBefore(
|
||||
response, 'Newest content', 'Middle content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
tests = [
|
||||
('order_by_expression', -9),
|
||||
('order_by_f_expression', -12),
|
||||
('order_by_orderby_expression', -13),
|
||||
]
|
||||
for admin_order_field, index in tests:
|
||||
with self.subTest(admin_order_field):
|
||||
response = self.client.get(
|
||||
reverse('admin:admin_views_article_changelist'),
|
||||
{'o': index},
|
||||
)
|
||||
self.assertContentBefore(
|
||||
response, 'Middle content', 'Oldest content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
self.assertContentBefore(
|
||||
response, 'Newest content', 'Middle content',
|
||||
'Results of sorting on callable are out of order.'
|
||||
)
|
||||
|
||||
def test_change_list_sorting_model(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user