def to(self, order):
        """
        Move object to a certain position, updating all affected objects to move accordingly up or down.
        """
        if order is None or getattr(self, self.order_field_name) == order:
            # object is already at desired position
            return
        qs = self.get_ordering_queryset()
        if getattr(self, self.order_field_name) > order:
            qs.filter(**{self.order_field_name + '__lt': getattr(self, self.order_field_name),
                         self.order_field_name + '__gte': order})\
              .update(**{self.order_field_name: F(self.order_field_name) + 1})
        else:
            qs.filter(**{self.order_field_name + '__gt': getattr(self, self.order_field_name),
                         self.order_field_name + '__lte': order})\
              .update(**{self.order_field_name: F(self.order_field_name) - 1})
        setattr(self, self.order_field_name, order)
        self.save()
dataset/ETHPy150Open bfirsh/django-ordered-model/ordered_model/models.py/OrderedModelBase.to/original