diff --git a/myproject/products/templates/products/variantgroup_form.html b/myproject/products/templates/products/variantgroup_form.html index 2f6ff3c..1074c86 100644 --- a/myproject/products/templates/products/variantgroup_form.html +++ b/myproject/products/templates/products/variantgroup_form.html @@ -293,9 +293,17 @@ document.addEventListener('DOMContentLoaded', function() { let priority = 1; container.querySelectorAll('.item-row:not([style*="display: none"])').forEach(row => { const priorityCell = row.querySelector('.item-priority'); - const priorityInput = row.querySelector('[name$="-priority"]'); - if (priorityCell) priorityCell.textContent = priority; - if (priorityInput) priorityInput.value = priority; + const priorityInput = row.querySelector('input[name$="-priority"]'); + + if (priorityCell) { + priorityCell.textContent = priority; + } + + if (priorityInput) { + priorityInput.value = priority; + console.log(`Обновлено поле приоритета: ${priorityInput.name} = ${priority}`); + } + priority++; }); } diff --git a/myproject/products/views/variant_group_views.py b/myproject/products/views/variant_group_views.py index 405f228..8256daf 100644 --- a/myproject/products/views/variant_group_views.py +++ b/myproject/products/views/variant_group_views.py @@ -170,11 +170,9 @@ class ProductVariantGroupUpdateView(LoginRequiredMixin, UpdateView): with transaction.atomic(): self.object = form.save(commit=True) items_formset.instance = self.object + # Сохраняем формсет, который содержит приоритеты установленные пользователем items_formset.save() - # Пересчитываем приоритеты после редактирования - self._recalculate_priorities(self.object) - messages.success( self.request, f'Группа вариантов "{self.object.name}" успешно обновлена!' @@ -184,14 +182,6 @@ class ProductVariantGroupUpdateView(LoginRequiredMixin, UpdateView): messages.error(self.request, f'Ошибка при сохранении: {str(e)}') return self.form_invalid(form) - @staticmethod - def _recalculate_priorities(variant_group): - """Пересчитывает приоритеты товаров в группе""" - items = variant_group.items.all().order_by('id') - for idx, item in enumerate(items, start=1): - item.priority = idx - item.save(update_fields=['priority']) - class ProductVariantGroupDeleteView(LoginRequiredMixin, DeleteView): """Удаление группы вариантов с подтверждением"""