mirror of
https://github.com/jazzband/django-admin-sortable.git
synced 2026-04-20 06:41:05 +00:00
Merge pull request #166 from sushifan/save-only-order-field
Only update the order field when saving objects; omit unnecessary db queries
This commit is contained in:
commit
0d92d5c1a1
1 changed files with 5 additions and 2 deletions
|
|
@ -297,8 +297,11 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
|
|||
|
||||
for index in indexes:
|
||||
obj = objects_dict.get(index)
|
||||
setattr(obj, order_field_name, start_index)
|
||||
obj.save()
|
||||
# perform the update only if 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