diff --git a/django/core/management/validation.py b/django/core/management/validation.py
index 3aaeaa9..f0b5b1c 100644
a
|
b
|
def get_validation_errors(outfile, app=None):
|
283 | 283 | # this format would be nice, but it's a little fiddly). |
284 | 284 | if '__' in field_name: |
285 | 285 | continue |
| 286 | # Skip ordering on pk, this is always a valid order_by field |
| 287 | # but is an alias and therefore won't be found by |
| 288 | # opts.get_field. |
| 289 | if field_name == 'pk': |
| 290 | continue |
286 | 291 | try: |
287 | 292 | opts.get_field(field_name, many_to_many=False) |
288 | 293 | except models.FieldDoesNotExist: |
diff --git a/tests/modeltests/invalid_models/invalid_models/models.py b/tests/modeltests/invalid_models/invalid_models/models.py
index 93c1c66..8909b5b 100644
a
|
b
|
class UnicodeForeignKeys(models.Model):
|
233 | 233 | class PrimaryKeyNull(models.Model): |
234 | 234 | my_pk_field = models.IntegerField(primary_key=True, null=True) |
235 | 235 | |
| 236 | class OrderByPKModel(models.Model): |
| 237 | """ |
| 238 | Model to test that ordering by pk passes validation. |
| 239 | Included due to https://code.djangoproject.com/ticket/8291 |
| 240 | """ |
| 241 | name = models.CharField(max_length=100, blank=True) |
| 242 | |
| 243 | class Meta: |
| 244 | ordering = ('pk',) |
236 | 245 | |
237 | 246 | model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer. |
238 | 247 | invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer. |
diff --git a/tests/modeltests/ordering/models.py b/tests/modeltests/ordering/models.py
index 25d3c2c..b2b84e1 100644
a
|
b
|
class Article(models.Model):
|
24 | 24 | |
25 | 25 | def __unicode__(self): |
26 | 26 | return self.headline |
| 27 | |
| 28 | class ArticlePKOrdering(models.Model): |
| 29 | headline = models.CharField(max_length=100) |
| 30 | pub_date = models.DateTimeField() |
| 31 | class Meta: |
| 32 | ordering = ('-pk',) |
| 33 | |
| 34 | def __unicode__(self): |
| 35 | return self.headline |
| 36 | |
diff --git a/tests/modeltests/ordering/tests.py b/tests/modeltests/ordering/tests.py
index 6a988b8..495cbeb 100644
a
|
b
|
from operator import attrgetter
|
5 | 5 | |
6 | 6 | from django.test import TestCase |
7 | 7 | |
8 | | from .models import Article |
| 8 | from .models import Article, ArticlePKOrdering |
9 | 9 | |
10 | 10 | |
11 | 11 | class OrderingTests(TestCase): |
… |
… |
class OrderingTests(TestCase):
|
137 | 137 | ], |
138 | 138 | attrgetter("headline") |
139 | 139 | ) |
| 140 | |
| 141 | |
| 142 | a1 = ArticlePKOrdering.objects.create( |
| 143 | pk=1, headline="Article 1", pub_date=datetime(2005, 7, 26) |
| 144 | ) |
| 145 | a2 = ArticlePKOrdering.objects.create( |
| 146 | pk=2, headline="Article 2", pub_date=datetime(2005, 7, 27) |
| 147 | ) |
| 148 | a3 = ArticlePKOrdering.objects.create( |
| 149 | pk=3, headline="Article 3", pub_date=datetime(2005, 7, 27) |
| 150 | ) |
| 151 | a4 = ArticlePKOrdering.objects.create( |
| 152 | pk=4, headline="Article 4", pub_date=datetime(2005, 7, 28) |
| 153 | ) |
| 154 | |
| 155 | self.assertQuerysetEqual( |
| 156 | ArticlePKOrdering.objects.all(), [ |
| 157 | "Article 4", |
| 158 | "Article 3", |
| 159 | "Article 2", |
| 160 | "Article 1", |
| 161 | ], |
| 162 | attrgetter("headline") |
| 163 | ) |
| 164 | |