Q objects
versus
or
Example: Query reading greater than 20 books, rewrite Q objects as follows.
from django.db.models import Q
BookInfo.objects.filter(Q(bread__gt=20))
- Q & objects may be used and | connected, & presentation logic, | represents logical OR.
Example: Read Query greater than 20, or less than the number of books 3, use only Q object implementation
BookInfo.objects.filter(Q(bread__gt=20) | Q(pk__lt=3))
non-
Q ~ operator using objects before, represents a non-not.
Example: the query number is not equal to 3 books.
BookInfo.objects.filter(~Q(pk=3))