Invert boolean field in update operations with F()

前端 未结 2 1310
臣服心动
臣服心动 2021-01-18 03:32

I need, through an update operation, revert a boolean value.

I tried:

Item.objects.filter(serial__in=license_ids).update(re         


        
2条回答
  •  粉色の甜心
    2021-01-18 04:20

    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))
        )
    )
    

提交回复
热议问题