code: def _update(qs):
          
          try:
              with transaction.atomic():
                  qs.update(sort_order=models.F('sort_order') + 1)
          except IntegrityError:
              for obj in qs.order_by('-sort_order'):
                  qs.filter(pk=obj.pk).update(sort_order=models.F('sort_order') + 1)
docs: Increment the sort_order in a queryset.
  
          Handle IntegrityErrors caused by unique constraints.