Anda dapat membuat kueri secara terprogram, menggunakan persyaratan Case
dan When
.
Jadi, misalnya:
from django.db.models import Case, When
# Make a list of When expressions
when_list = [When(priority_number=2, then=3),
When(priority_number=3, then=4)]
# Use in a query of your choice, as an example:
Model.objects.update(
priority_number=Case(
*when_list))