def save(self, *args, **kwargs):
objects = self.get_filtered_manager()<EOL>old_pos = getattr(self, '<STR_LIT>', None)<EOL>new_pos = self.sort_order<EOL>if old_pos is None and self._unique_togethers_changed():<EOL><INDENT>self.sort_order = None<EOL>new_pos = None<EOL><DEDENT>try:<EOL><INDENT>with transaction.atomic():<EOL><INDENT>self._save(objects, old_pos, new_pos)<EOL><DEDENT><DEDENT>except IntegrityError:<EOL><INDENT>with transaction.atomic():<EOL><INDENT>old_pos = objects.filter(pk=self.pk).values_list(<EOL>'<STR_LIT>', flat=True)[<NUM_LIT:0>]<EOL>self._save(objects, old_pos, new_pos)<EOL><DEDENT><DEDENT>super(Orderable, self).save(*args, **kwargs)<EOL>
Keep the unique order in sync.