diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-12-27 19:47:14 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-12-27 19:49:15 +0100 |
| commit | 8f67eeaef44ae8f1fcb51588a65f7818e4d7a967 (patch) | |
| tree | 17285874860a618c00791f4ce079787b63d1d0f5 | |
| parent | b54302d2269e54cfc2a9594b1f3e652e1fd089ed (diff) | |
[2.0.x] 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.
Backport of 1d00923848d504c6132019492b8d5a6cdf8261db from master
| -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. |
