Use 'update_fields' to limit the object's save() method to just the order field, so that other fields are not accidentally overwritten with stale data.

master
Anton Shevchenko 2017-03-08 22:14:48 -05:00
parent 99530d3ba4
commit f2f5daf831
1 changed files with 2 additions and 1 deletions

View File

@ -298,7 +298,8 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
for index in indexes: for index in indexes:
obj = objects_dict.get(index) obj = objects_dict.get(index)
setattr(obj, order_field_name, start_index) setattr(obj, order_field_name, start_index)
obj.save() # only update the object's order field
obj.save(update_fields=(order_field_name,))
start_index += step start_index += step
response = {'objects_sorted': True} response = {'objects_sorted': True}
except (KeyError, IndexError, klass.DoesNotExist, except (KeyError, IndexError, klass.DoesNotExist,