@@ -419,22 +419,22 @@ models doesn't have a value that meets the filter condition, Django will treat
419
419
it as if there is an empty (all values are ``NULL``), but valid, object there.
420
420
All this means is that no error will be raised. For example, in this filter::
421
421
422
- Blog.objects.filter(entry__author__name ='Lennon')
422
+ Blog.objects.filter(entry__authors__name ='Lennon')
423
423
424
424
(if there was a related ``Author`` model), if there was no ``author``
425
425
associated with an entry, it would be treated as if there was also no ``name``
426
426
attached, rather than raising an error because of the missing ``author``.
427
427
Usually this is exactly what you want to have happen. The only case where it
428
428
might be confusing is if you are using ``isnull``. Thus::
429
429
430
- Blog.objects.filter(entry__author__name__isnull =True)
430
+ Blog.objects.filter(entry__authors__name__isnull =True)
431
431
432
432
will return ``Blog`` objects that have an empty ``name`` on the ``author`` and
433
433
also those which have an empty ``author`` on the ``entry``. If you don't want
434
434
those latter objects, you could write::
435
435
436
- Blog.objects.filter(entry__author__isnull =False,
437
- entry__author__name__isnull =True)
436
+ Blog.objects.filter(entry__authors__isnull =False,
437
+ entry__authors__name__isnull =True)
438
438
439
439
Spanning multi-valued relationships
440
440
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -532,7 +532,7 @@ any joins needed to access the related object. For example, to retrieve all
532
532
the entries where the author's name is the same as the blog name, we could
533
533
issue the query:
534
534
535
- >>> Entry.objects.filter(author__name =F('blog__name'))
535
+ >>> Entry.objects.filter(authors__name =F('blog__name'))
536
536
537
537
The pk lookup shortcut
538
538
----------------------
0 commit comments