mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #21924 -- Added the ability to specify a reverse order for admin_order_field.
Thanks Klemens Mantzos for the report and initial patch.
This commit is contained in:
committed by
Tim Graham
parent
0242134d32
commit
f683cb90be
@@ -260,7 +260,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
||||
def testChangeListSortingModelAdmin(self):
|
||||
"""
|
||||
Ensure we can sort on a list_display field that is a ModelAdmin method
|
||||
(colunn 4 is 'modeladmin_year' in ArticleAdmin)
|
||||
(column 4 is 'modeladmin_year' in ArticleAdmin)
|
||||
"""
|
||||
response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'o': '4'})
|
||||
self.assertContentBefore(response, 'Oldest content', 'Middle content',
|
||||
@@ -268,6 +268,25 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
||||
self.assertContentBefore(response, 'Middle content', 'Newest content',
|
||||
"Results of sorting on ModelAdmin method are out of order.")
|
||||
|
||||
def testChangeListSortingModelAdminReverse(self):
|
||||
"""
|
||||
Ensure we can sort on a list_display field that is a ModelAdmin
|
||||
method in reverse order (i.e. admin_order_field uses the '-' prefix)
|
||||
(column 6 is 'model_year_reverse' in ArticleAdmin)
|
||||
"""
|
||||
response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'o': '6'})
|
||||
self.assertContentBefore(response, '2009', '2008',
|
||||
"Results of sorting on ModelAdmin method are out of order.")
|
||||
self.assertContentBefore(response, '2008', '2000',
|
||||
"Results of sorting on ModelAdmin method are out of order.")
|
||||
# Let's make sure the ordering is right and that we don't get a
|
||||
# FieldError when we change to descending order
|
||||
response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'o': '-6'})
|
||||
self.assertContentBefore(response, '2000', '2008',
|
||||
"Results of sorting on ModelAdmin method are out of order.")
|
||||
self.assertContentBefore(response, '2008', '2009',
|
||||
"Results of sorting on ModelAdmin method are out of order.")
|
||||
|
||||
def testChangeListSortingMultiple(self):
|
||||
p1 = Person.objects.create(name="Chris", gender=1, alive=True)
|
||||
p2 = Person.objects.create(name="Chris", gender=2, alive=True)
|
||||
|
||||
Reference in New Issue
Block a user