Fixed #16211 -- Added logical NOT support to F expressions.

This commit is contained in:
David Wobrock 2022-09-26 22:59:25 +02:00 committed by Mariusz Felisiak
parent c01e76c95c
commit a320aab512
7 changed files with 164 additions and 29 deletions

View file

@ -255,6 +255,19 @@ is null) after companies that have been contacted::
from django.db.models import F
Company.objects.order_by(F('last_contacted').desc(nulls_last=True))
Using ``F()`` with logical operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 4.2
``F()`` expressions that output ``BooleanField`` can be logically negated with
the inversion operator ``~F()``. For example, to swap the activation status of
companies::
from django.db.models import F
Company.objects.update(is_active=~F('is_active'))
.. _func-expressions:
``Func()`` expressions