diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-12-27 19:47:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-27 19:47:14 +0100 |
commit | 1d00923848d504c6132019492b8d5a6cdf8261db (patch) | |
tree | f7a608d9d26107a5147bbba407ef8155df1218fc /tests/admin_ordering | |
parent | c8152137400b5932578cd1788b79560c9772e56b (diff) | |
download | django-1d00923848d504c6132019492b8d5a6cdf8261db.tar.gz |
Refs #28958 -- Added a test for ModelAdmin with query expressions in ordering.
This provides additional test coverage but isn't a regression test for
the ticket's issue.
Diffstat (limited to 'tests/admin_ordering')
-rw-r--r-- | tests/admin_ordering/tests.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/admin_ordering/tests.py b/tests/admin_ordering/tests.py index 74a6b8b24b..8de35fa32c 100644 --- a/tests/admin_ordering/tests.py +++ b/tests/admin_ordering/tests.py @@ -1,6 +1,7 @@ from django.contrib import admin from django.contrib.admin.options import ModelAdmin from django.contrib.auth.models import User +from django.db.models import F from django.test import RequestFactory, TestCase from .models import ( @@ -62,6 +63,13 @@ class TestAdminOrdering(TestCase): names = [b.name for b in ma.get_queryset(request)] self.assertEqual(['Radiohead', 'Van Halen', 'Aerosmith'], names) + def test_specified_ordering_by_f_expression(self): + class BandAdmin(ModelAdmin): + ordering = (F('rank').desc(nulls_last=True),) + band_admin = BandAdmin(Band, site) + names = [b.name for b in band_admin.get_queryset(request)] + self.assertEqual(['Aerosmith', 'Van Halen', 'Radiohead'], names) + def test_dynamic_ordering(self): """ Let's use a custom ModelAdmin that changes the ordering dynamically. |