Fixed #8291 -- Allowed 'pk' to be used as an ordering option in Model.Meta. Thanks to peterd12 for the report and to evan_schulz, gruszczy, frog32 and David Gouldin for their work on the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17445 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Julien Phalip 2012-02-04 19:56:40 +00:00
parent 3db80c4c05
commit d3154d1896
4 changed files with 52 additions and 1 deletions

View file

@ -5,7 +5,7 @@ from operator import attrgetter
from django.test import TestCase
from .models import Article
from .models import Article, ArticlePKOrdering
class OrderingTests(TestCase):
@ -137,3 +137,31 @@ class OrderingTests(TestCase):
],
attrgetter("headline")
)
def test_order_by_pk(self):
"""
Ensure that 'pk' works as an ordering option in Meta.
Refs #8291.
"""
a1 = ArticlePKOrdering.objects.create(
pk=1, headline="Article 1", pub_date=datetime(2005, 7, 26)
)
a2 = ArticlePKOrdering.objects.create(
pk=2, headline="Article 2", pub_date=datetime(2005, 7, 27)
)
a3 = ArticlePKOrdering.objects.create(
pk=3, headline="Article 3", pub_date=datetime(2005, 7, 27)
)
a4 = ArticlePKOrdering.objects.create(
pk=4, headline="Article 4", pub_date=datetime(2005, 7, 28)
)
self.assertQuerysetEqual(
ArticlePKOrdering.objects.all(), [
"Article 4",
"Article 3",
"Article 2",
"Article 1",
],
attrgetter("headline")
)