Ticket #10955: 10955-proxy_select_related-r10643.diff
File 10955-proxy_select_related-r10643.diff, 1.5 KB (added by , 16 years ago) |
---|
-
tests/modeltests/proxy_models/models.py
82 82 class LowerStatusPerson(MyPersonProxy): 83 83 status = models.CharField(max_length=80) 84 84 85 # We can still use `select_related()` to include related models in our querysets. 86 class Country(models.Model): 87 name = models.CharField(max_length=50) 88 89 class State(models.Model): 90 name = models.CharField(max_length=50) 91 country = models.ForeignKey(Country) 92 93 def __unicode__(self): 94 return self.name 95 96 class StateProxy(State): 97 class Meta: 98 proxy = True 99 85 100 __test__ = {'API_TESTS' : """ 86 101 # The MyPerson model should be generating the same database queries as the 87 102 # Person model (when the same manager is used in each case). … … 178 193 >>> ctype = ContentType.objects.get_for_model 179 194 >>> ctype(Person) is ctype(OtherPerson) 180 195 True 181 """}182 196 197 # We can still use `select_related()` to include related models in our querysets. 198 >>> country = Country.objects.create(name='Australia') 199 >>> state = State.objects.create(name='New South Wales', country=country) 183 200 201 >>> State.objects.select_related() 202 [<State: New South Wales>] 203 >>> StateProxy.objects.select_related() 204 [<StateProxy: New South Wales>] 205 >>> StateProxy.objects.get(name='New South Wales') 206 <StateProxy: New South Wales> 207 >>> StateProxy.objects.select_related().get(name='New South Wales') 208 [<StateProxy: New South Wales>] 209 """}