Django ORM Q对象

时间:2018-10-11 17:40:19

标签: django orm django-queryset q

之间的区别是什么

books = Book.objects.filter(name__in=names,film__isnull=True)
books = books.union(Book.objects.filter(name__in=names,film__date__lte=date)).distinct("id")

VS

from django.db.models import Q
books = Book.objects.filter(Q(name__in=names),Q(film__date__lte=date)| Q(film__isnull=True)).distinct(id)

和之间的区别是什么?

[...].filter(
    Q(hide=False) & Q(deleted=False),
    Q(stock=False) | Q(quantity__gte=1))

VS

[...].filter(
    Q(hide=False),Q(deleted=False),
    Q(stock=False) | Q(quantity__gte=1))

thx

0 个答案:

没有答案