mirror of
https://github.com/jazzband/django-admin-sortable.git
synced 2026-03-16 22:10:30 +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:
|
||||
obj = objects_dict.get(index)
|
||||
setattr(obj, order_field_name, start_index)
|
||||
# only update the object's order field
|
||||
obj.save(update_fields=(order_field_name,))
|
||||
# perform the update iff the order field has changed
|
||||
if getattr(obj, order_field_name) != start_index:
|
||||
setattr(obj, order_field_name, start_index)
|
||||
# only update the object's order field
|
||||
obj.save(update_fields=(order_field_name,))
|
||||
start_index += step
|
||||
response = {'objects_sorted': True}
|
||||
except (KeyError, IndexError, klass.DoesNotExist,
|
||||
|
|
|
|||
Loading…
Reference in a new issue