| 220 | # OR lookups across foreign keys |
| 221 | # |
| 222 | # At revision 3077, the last test case fails to find Luke. An inner |
| 223 | # join is created, and since Luke has no articles, he doesn't match |
| 224 | # the criteria. For someone not familiar with how the ORM works, it's |
| 225 | # quite unexpected. |
| 226 | >>> from django.db.models import Q |
| 227 | >>> Reporter.objects.filter(Q(first_name='John')|Q(article__headline__startswith='Paul')).distinct() |
| 228 | [<Reporter: John Smith>, <Reporter: Paul Jones>] |
| 229 | >>> r3 = Reporter(first_name='Luke', last_name='Field', email='luke@example.com') |
| 230 | >>> r3.save() |
| 231 | >>> Reporter.objects.filter(Q(first_name='Luke')|Q(article__headline__startswith='Paul')).distinct() |
| 232 | [<Reporter: Luke Field>, <Reporter: Paul Jones>] |
| 233 | >>> r3.delete() |
| 234 | |