summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKlemens Mantzos <klemens@fetzig.at>2014-01-23 03:13:59 +0100
committerTim Graham <timograham@gmail.com>2014-02-14 19:53:44 -0500
commitf683cb90bea2afbe0ef4c011acd4ab590c37410d (patch)
treefdb2b7528378f60979fd5e32a27ae80594626962 /tests
parent0242134d32aa99a54442211ed05576b7061866d1 (diff)
downloaddjango-f683cb90bea2afbe0ef4c011acd4ab590c37410d.tar.gz
Fixed #21924 -- Added the ability to specify a reverse order for admin_order_field.
Thanks Klemens Mantzos for the report and initial patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_views/admin.py3
-rw-r--r--tests/admin_views/models.py5
-rw-r--r--tests/admin_views/tests.py21
3 files changed, 27 insertions, 2 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index e17942e831..ae625b6a53 100644
--- a/tests/admin_views/admin.py
+++ b/tests/admin_views/admin.py
@@ -76,7 +76,8 @@ class ChapterXtra1Admin(admin.ModelAdmin):
class ArticleAdmin(admin.ModelAdmin):
- list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year')
+ list_display = ('content', 'date', callable_year, 'model_year',
+ 'modeladmin_year', 'model_year_reversed')
list_filter = ('date', 'section')
view_on_site = False
fieldsets = (
diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py
index 4cc58f5e88..c729f6b90a 100644
--- a/tests/admin_views/models.py
+++ b/tests/admin_views/models.py
@@ -41,6 +41,11 @@ class Article(models.Model):
model_year.admin_order_field = 'date'
model_year.short_description = ''
+ def model_year_reversed(self):
+ return self.date.year
+ model_year_reversed.admin_order_field = '-date'
+ model_year_reversed.short_description = ''
+
@python_2_unicode_compatible
class Book(models.Model):
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index f5c90bc1d0..41ac47bafd 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -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)