mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[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 1d00923848 from master
			
			
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| from django.contrib import admin | from django.contrib import admin | ||||||
| from django.contrib.admin.options import ModelAdmin | from django.contrib.admin.options import ModelAdmin | ||||||
| from django.contrib.auth.models import User | from django.contrib.auth.models import User | ||||||
|  | from django.db.models import F | ||||||
| from django.test import RequestFactory, TestCase | from django.test import RequestFactory, TestCase | ||||||
|  |  | ||||||
| from .models import ( | from .models import ( | ||||||
| @@ -62,6 +63,13 @@ class TestAdminOrdering(TestCase): | |||||||
|         names = [b.name for b in ma.get_queryset(request)] |         names = [b.name for b in ma.get_queryset(request)] | ||||||
|         self.assertEqual(['Radiohead', 'Van Halen', 'Aerosmith'], names) |         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): |     def test_dynamic_ordering(self): | ||||||
|         """ |         """ | ||||||
|         Let's use a custom ModelAdmin that changes the ordering dynamically. |         Let's use a custom ModelAdmin that changes the ordering dynamically. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user