From 2aa3de7bfa2cd52e96d6a411250515063d483460 Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Tue, 13 Jan 2026 10:04:48 +0300 Subject: [PATCH] =?UTF-8?q?feat(products):=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=82=D1=8C=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=20=D0=BC=D0=B0=D1=80=D0=BA=D0=B5=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3=D0=BE=D0=B2=D1=8B=D1=85=20=D1=84=D0=BB=D0=B0=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавлены поля is_new, is_popular, is_special в форму продукта. Настроено отображение полей в виде переключателей (switch). Добавлено отображение бейджей флагов в списке товаров и на странице детализации продукта. --- myproject/products/forms.py | 10 ++++- .../templates/products/product_detail.html | 17 +++++++++ .../templates/products/product_form.html | 37 +++++++++++++++++++ .../templates/products/products_list.html | 5 +++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/myproject/products/forms.py b/myproject/products/forms.py index 13993f8..7026d2b 100644 --- a/myproject/products/forms.py +++ b/myproject/products/forms.py @@ -98,7 +98,8 @@ class ProductForm(SKUUniqueMixin, forms.ModelForm): model = Product fields = [ 'name', 'sku', 'description', 'short_description', 'categories', - 'tags', 'base_unit', 'price', 'sale_price', 'status' + 'tags', 'base_unit', 'price', 'sale_price', 'status', + 'is_new', 'is_popular', 'is_special' ] labels = { 'name': 'Название', @@ -149,6 +150,13 @@ class ProductForm(SKUUniqueMixin, forms.ModelForm): self.fields['base_unit'].required = False self.fields['base_unit'].help_text = 'Базовая единица для учета товара на складе. На основе этой единицы можно создать единицы продажи.' + # Маркетинговые флаги (switch-стиль) + for flag_field in ['is_new', 'is_popular', 'is_special']: + self.fields[flag_field].widget.attrs.update({ + 'class': 'form-check-input', + 'role': 'switch' + }) + def clean_name(self): """Валидация уникальности имени для активных товаров""" name = self.cleaned_data.get('name') diff --git a/myproject/products/templates/products/product_detail.html b/myproject/products/templates/products/product_detail.html index 56928ee..00f3de8 100644 --- a/myproject/products/templates/products/product_detail.html +++ b/myproject/products/templates/products/product_detail.html @@ -338,6 +338,23 @@ {% endif %} + + Маркетинговые флаги: + + {% if product.is_new %} + Новинка + {% endif %} + {% if product.is_popular %} + Популярный + {% endif %} + {% if product.is_special %} + Спецпредложение + {% endif %} + {% if not product.is_new and not product.is_popular and not product.is_special %} + - + {% endif %} + + Дата создания: {{ product.created_at }} diff --git a/myproject/products/templates/products/product_form.html b/myproject/products/templates/products/product_form.html index 9100d3d..ea68cc0 100644 --- a/myproject/products/templates/products/product_form.html +++ b/myproject/products/templates/products/product_form.html @@ -530,6 +530,43 @@
+ +
+
Маркетинговые флаги
+

Отображаются на внешних площадках (Recommerce и др.)

+
+
+
+ {{ form.is_new }} + +
+ Товар отображается как новый +
+
+
+ {{ form.is_popular }} + +
+ Товар отображается как популярный +
+
+
+ {{ form.is_special }} + +
+ Акционный товар (+ автоматически при скидке) +
+
+
+ +
+ {% if object %}
diff --git a/myproject/products/templates/products/products_list.html b/myproject/products/templates/products/products_list.html index 6ce9f1c..9d02fab 100644 --- a/myproject/products/templates/products/products_list.html +++ b/myproject/products/templates/products/products_list.html @@ -246,6 +246,11 @@ {% else %} {{ item.name }} {% endif %} +
+ {% if item.is_new %}{% endif %} + {% if item.is_popular %}{% endif %} + {% if item.is_special %}{% endif %} +
{{ item.sku }}