From a320aab5129f4019b3c1d28b7a3b509582bc56f9 Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Mon, 26 Sep 2022 22:59:25 +0200 Subject: Fixed #16211 -- Added logical NOT support to F expressions. --- docs/ref/models/expressions.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docs/ref/models') diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt index ccd18670b1..e1edad2e4d 100644 --- a/docs/ref/models/expressions.txt +++ b/docs/ref/models/expressions.txt @@ -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 -- cgit v1.3