mirror of
https://github.com/django/django.git
synced 2025-11-02 04:48:33 +00:00
Fixed #18355 -- Added ordering options to list based generic views.
Added MultipleObjectMixin.ordering and get_ordering(). Refs #21450.
This commit is contained in:
parent
0ad4672c0f
commit
2724cdbff6
9 changed files with 126 additions and 7 deletions
|
|
@ -1,11 +1,13 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import TestCase, override_settings
|
||||
from django.views.generic.base import View
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
from .models import Author, Artist
|
||||
from .models import Author, Artist, Book
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='generic_views.urls')
|
||||
|
|
@ -200,6 +202,20 @@ class ListViewTests(TestCase):
|
|||
with self.assertNumQueries(3):
|
||||
self.client.get('/list/authors/notempty/paginated/')
|
||||
|
||||
def test_explicitly_ordered_list_view(self):
|
||||
Book.objects.create(name="Zebras for Dummies", pages=800, pubdate=datetime.date(2006, 9, 1))
|
||||
res = self.client.get('/list/books/sorted/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertEqual(res.context['object_list'][0].name, '2066')
|
||||
self.assertEqual(res.context['object_list'][1].name, 'Dreaming in Code')
|
||||
self.assertEqual(res.context['object_list'][2].name, 'Zebras for Dummies')
|
||||
|
||||
res = self.client.get('/list/books/sortedbypagesandnamedec/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertEqual(res.context['object_list'][0].name, 'Dreaming in Code')
|
||||
self.assertEqual(res.context['object_list'][1].name, 'Zebras for Dummies')
|
||||
self.assertEqual(res.context['object_list'][2].name, '2066')
|
||||
|
||||
@override_settings(DEBUG=True)
|
||||
def test_paginated_list_view_returns_useful_message_on_invalid_page(self):
|
||||
# test for #19240
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue