Ticket #8291: 8291_django_con11.diff
File 8291_django_con11.diff, 3.3 KB (added by , 13 years ago) |
---|
-
django/db/models/options.py
277 277 """ 278 278 Returns the requested field by name. Raises FieldDoesNotExist on error. 279 279 """ 280 if name == 'pk': # replace special value "pk" with primary key attribute name 281 attname = self.pk.attname 282 else: 283 attname = name 280 284 to_search = many_to_many and (self.fields + self.many_to_many) or self.fields 281 285 for f in to_search: 282 if f.name == name:286 if f.name == attname: 283 287 return f 284 288 raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, name)) 285 289 -
django/core/management/validation.py
284 284 # this format would be nice, but it's a little fiddly). 285 285 if '__' in field_name: 286 286 continue 287 if field_name == 'pk': 288 continue 287 289 try: 288 290 opts.get_field(field_name, many_to_many=False) 289 291 except models.FieldDoesNotExist: -
tests/modeltests/ordering/tests.py
3 3 4 4 from django.test import TestCase 5 5 6 from models import Article 6 from models import Article, ArticleWithPKReverseDefaultOrdering 7 7 8 8 9 9 class OrderingTests(TestCase): … … 135 135 ], 136 136 attrgetter("headline") 137 137 ) 138 139 a1 = ArticleWithPKReverseDefaultOrdering.objects.create( 140 pk=1, headline="Article 1", pub_date=datetime(2005, 7, 26) 141 ) 142 a2 = ArticleWithPKReverseDefaultOrdering.objects.create( 143 pk=2, headline="Article 2", pub_date=datetime(2005, 7, 27) 144 ) 145 a3 = ArticleWithPKReverseDefaultOrdering.objects.create( 146 pk=3, headline="Article 3", pub_date=datetime(2005, 7, 27) 147 ) 148 a4 = ArticleWithPKReverseDefaultOrdering.objects.create( 149 pk=4, headline="Article 4", pub_date=datetime(2005, 7, 28) 150 ) 151 152 self.assertQuerysetEqual( 153 ArticleWithPKReverseDefaultOrdering.objects.all(), [ 154 "Article 4", 155 "Article 3", 156 "Article 2", 157 "Article 1", 158 ], 159 attrgetter("headline") 160 ) 161 162 No newline at end of file -
tests/modeltests/ordering/models.py
24 24 25 25 def __unicode__(self): 26 26 return self.headline 27 28 class ArticleWithPKReverseDefaultOrdering(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