Ticket #8291: 8291_2.diff
File 8291_2.diff, 2.2 KB (added by , 16 years ago) |
---|
-
django/db/models/options.py
253 253 self._m2m_cache = cache 254 254 255 255 def get_field(self, name, many_to_many=True): 256 if name == 'pk': # replace special value "pk" with primary key attribute name 257 attname = self.pk.attname 258 else: 259 attname = name 256 260 """ 257 261 Returns the requested field by name. Raises FieldDoesNotExist on error. 258 262 """ 259 263 to_search = many_to_many and (self.fields + self.many_to_many) or self.fields 260 264 for f in to_search: 261 if f.name == name:265 if f.name == attname: 262 266 return f 263 267 raise FieldDoesNotExist, '%s has no field named %r' % (self.object_name, name) 264 268 -
tests/modeltests/ordering/models.py
24 24 def __unicode__(self): 25 25 return self.headline 26 26 27 class Writer(models.Model): 28 name = models.CharField(max_length=50) 29 class Meta: 30 ordering = ('pk',) 31 32 def __unicode__(self): 33 return self.name 34 27 35 __test__ = {'API_TESTS':""" 28 36 # Create a couple of Articles. 29 37 >>> from datetime import datetime … … 36 44 >>> a4 = Article(headline='Article 4', pub_date=datetime(2005, 7, 28)) 37 45 >>> a4.save() 38 46 47 # Create a couple of Writers. 48 >>> w1 = Writer(name='Kurt Vonnegut') 49 >>> w1.save() 50 >>> w2 = Writer(name='Joseph Heller') 51 >>> w2.save() 52 >>> w3 = Writer(name='Douglas Adams') 53 >>> w3.save() 54 39 55 # By default, Article.objects.all() orders by pub_date descending, then 40 56 # headline ascending. 41 57 >>> Article.objects.all() … … 86 102 >>> Article.objects.extra(select={'order': 'pub_date'}, order_by=['order', 'headline']) 87 103 [<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>] 88 104 105 # Use the special value 'pk' to order on the primary key field 106 >>> Writer.objects.order_by('pk') 107 [<Writer: Kurt Vonnegut>, <Writer: Joseph Heller>, <Writer: Douglas Adams>] 89 108 """}