Invert boolean field in update operations with F()
django
Solution
Not is not supported here. You will have to use Case When
from django.db.models import Case, Value, When
Item.objects.filter(serial__in=license_ids
).update(renewable=Case(
When(renewable=True, then=Value(False)),
default=Value(True))
)
)
Problem
I need, through an `update` operation, revert a `boolean` value. I tried: ``` Item.objects.filter(serial__in=license_ids).update(renewable=not F('renewable')) ``` But it doesn't work. I made sure the fields are not set to `null`.