<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _update(qs):
 """ Increment the sort_order in a queryset. Handle IntegrityErrors caused by unique constraints. """

        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)