| 52 | # Models for testing bug #8036. |
| 53 | class Country(models.Model): |
| 54 | name = models.CharField(max_length=50) |
| 55 | |
| 56 | class State(models.Model): |
| 57 | name = models.CharField(max_length=50) |
| 58 | country = models.ForeignKey(Country) |
| 59 | |
| 60 | class ClientStatus(models.Model): |
| 61 | name = models.CharField(max_length=50) |
| 62 | |
| 63 | class Client(models.Model): |
| 64 | name = models.CharField(max_length=50) |
| 65 | state = models.ForeignKey(State, null=True) |
| 66 | status = models.ForeignKey(ClientStatus) |
| 67 | |
| 119 | |
| 120 | Regression test for bug #8036. |
| 121 | |
| 122 | >>> australia = Country.objects.create(name='Australia') |
| 123 | >>> active = ClientStatus.objects.create(name='active') |
| 124 | >>> client = Client.objects.create(name='client', status=active) |
| 125 | |
| 126 | >>> client.status |
| 127 | <ClientStatus: ClientStatus object> |
| 128 | >>> Client.objects.select_related().latest('id').status |
| 129 | <ClientStatus: ClientStatus object> |
| 130 | >>> Client.objects.select_related('state').latest('id').status |
| 131 | <ClientStatus: ClientStatus object> |
| 132 | >>> Client.objects.select_related('state', 'status').latest('id').status |
| 133 | <ClientStatus: ClientStatus object> |
| 134 | >>> Client.objects.select_related('state__country').latest('id').status |
| 135 | <ClientStatus: ClientStatus object> |
| 136 | >>> Client.objects.select_related('state__country', 'status').latest('id').status |
| 137 | <ClientStatus: ClientStatus object> |
| 138 | >>> Client.objects.select_related('status').latest('id').status |
| 139 | <ClientStatus: ClientStatus object> |