6👍
✅
You should create only the When
s in loop and put them inside a single Case
.
whens = [When(id=id, then=Value(str(id))) for id in ids] # make a list
Employee.objects.update(
account_type=Case(
*whens # unpack the list
),
)
Source:stackexchange.com