Ticket #8291: 8291_last_patch_evar.diff

File 8291_last_patch_evar.diff, 3.6 KB (added by David Gouldin, 12 years ago)
  • django/core/management/validation.py

    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):  
    283283                # this format would be nice, but it's a little fiddly).
    284284                if '__' in field_name:
    285285                    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
    286291                try:
    287292                    opts.get_field(field_name, many_to_many=False)
    288293                except models.FieldDoesNotExist:
  • tests/modeltests/invalid_models/invalid_models/models.py

    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):  
    233233class PrimaryKeyNull(models.Model):
    234234    my_pk_field = models.IntegerField(primary_key=True, null=True)
    235235
     236class 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',)
    236245
    237246model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
    238247invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
  • tests/modeltests/ordering/models.py

    diff --git a/tests/modeltests/ordering/models.py b/tests/modeltests/ordering/models.py
    index 25d3c2c..b2b84e1 100644
    a b class Article(models.Model):  
    2424
    2525    def __unicode__(self):
    2626        return self.headline
     27
     28class 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
  • tests/modeltests/ordering/tests.py

    diff --git a/tests/modeltests/ordering/tests.py b/tests/modeltests/ordering/tests.py
    index 6a988b8..495cbeb 100644
    a b from operator import attrgetter  
    55
    66from django.test import TestCase
    77
    8 from .models import Article
     8from .models import Article, ArticlePKOrdering
    99
    1010
    1111class OrderingTests(TestCase):
    class OrderingTests(TestCase):  
    137137            ],
    138138            attrgetter("headline")
    139139        )
     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
Back to Top