def _save(self, objects, old_pos, new_pos):
to_shift = objects.exclude(pk=self.pk) if self.pk else objects<EOL>if self.sort_order is None:<EOL><INDENT>self._move_to_end(objects)<EOL><DEDENT>elif not self.pk and not old_pos:<EOL><INDENT>to_shift = to_shift.filter(sort_order__gte=self.sort_order)<EOL>self._update(to_shift)<EOL>self.sort_order = new_pos<EOL><DEDENT>elif old_pos and new_pos < old_pos:<EOL><INDENT>self._move_to_end(objects)<EOL>super(Orderable, self).save()<EOL>to_shift = to_shift.filter(sort_order__gte=new_pos, sort_order__lt=old_pos)<EOL>self._update(to_shift)<EOL>self.sort_order = new_pos<EOL><DEDENT>elif old_pos and new_pos > old_pos:<EOL><INDENT>self._move_to_end(objects)<EOL>super(Orderable, self).save()<EOL>to_shift = to_shift.filter(sort_order__lte=new_pos, sort_order__gt=old_pos)<EOL>to_shift.update(sort_order=models.F('<STR_LIT>') - <NUM_LIT:1>)<EOL>self.sort_order = new_pos<EOL><DEDENT>
WARNING: Intensive giggery-pokery zone.