Avoid unnecessary db queries: perform the update iff the order field has changed.
parent
f2f5daf831
commit
eb5a9e0a8a
|
|
@ -297,6 +297,8 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
|
||||||
|
|
||||||
for index in indexes:
|
for index in indexes:
|
||||||
obj = objects_dict.get(index)
|
obj = objects_dict.get(index)
|
||||||
|
# perform the update iff the order field has changed
|
||||||
|
if getattr(obj, order_field_name) != start_index:
|
||||||
setattr(obj, order_field_name, start_index)
|
setattr(obj, order_field_name, start_index)
|
||||||
# only update the object's order field
|
# only update the object's order field
|
||||||
obj.save(update_fields=(order_field_name,))
|
obj.save(update_fields=(order_field_name,))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue