mirror of
https://github.com/jazzband/django-admin-sortable.git
synced 2026-05-28 16:28:18 +00:00
Avoid unnecessary db queries: perform the update iff the order field has changed.
This commit is contained in:
parent
f2f5daf831
commit
eb5a9e0a8a
1 changed files with 5 additions and 3 deletions
|
|
@ -297,9 +297,11 @@ 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)
|
# perform the update iff the order field has changed
|
||||||
# only update the object's order field
|
if getattr(obj, order_field_name) != start_index:
|
||||||
obj.save(update_fields=(order_field_name,))
|
setattr(obj, order_field_name, start_index)
|
||||||
|
# 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,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue