Ticket #10955: 10955-proxy_select_related-r10643.diff

File 10955-proxy_select_related-r10643.diff, 1.5 KB (added by Tai Lee, 16 years ago)
  • tests/modeltests/proxy_models/models.py

     
    8282class LowerStatusPerson(MyPersonProxy):
    8383    status = models.CharField(max_length=80)
    8484
     85# We can still use `select_related()` to include related models in our querysets.
     86class Country(models.Model):
     87        name = models.CharField(max_length=50)
     88
     89class 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
     96class StateProxy(State):
     97        class Meta:
     98                proxy = True
     99
    85100__test__ = {'API_TESTS' : """
    86101# The MyPerson model should be generating the same database queries as the
    87102# Person model (when the same manager is used in each case).
     
    178193>>> ctype = ContentType.objects.get_for_model
    179194>>> ctype(Person) is ctype(OtherPerson)
    180195True
    181 """}
    182196
     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)
    183200
     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"""}
Back to Top