diff --git a/backend/core/settings/unfold_conf.py b/backend/core/settings/unfold_conf.py index 44f5e63..a143954 100644 --- a/backend/core/settings/unfold_conf.py +++ b/backend/core/settings/unfold_conf.py @@ -268,6 +268,11 @@ UNFOLD = { "icon": "photo_prints", "link": reverse_lazy("admin:product_productvariant_changelist"), }, + { + "title": _("بخش جزيیات محصول"), + "icon": "subject", + "link": reverse_lazy("admin:product_productdetailmodel_changelist"), + }, ], }, diff --git a/backend/product/admin.py b/backend/product/admin.py index a7d6e19..14f7458 100644 --- a/backend/product/admin.py +++ b/backend/product/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin, messages +from product.tasks import update_prices from .models import * from unfold.admin import TabularInline, StackedInline from home.models import LearnVideoModel @@ -122,7 +123,7 @@ class DetailModelAdmin(ModelAdmin, ImportExportModelAdmin): class ProductDetailModel1Admin(ModelAdmin, ImportExportModelAdmin): import_form_class = ImportForm export_form_class = ExportForm - search_fields = ['detail_category__title'] + search_fields = ['detail_category__title', 'name'] compressed_fields = True warn_unsaved_form = True @@ -216,8 +217,7 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin): @action(description=f"اپدیت قیمت ها") def update_products_price(self, request): - print('from the button') - ProductVariant.update_all_prices() + # update_prices() messages.success(request, f"قیمت {ProductVariant.objects.all().count()} تنوع محصول اپدیت شد") return redirect("admin:product_productmodel_changelist") diff --git a/backend/product/migrations/0037_productdetailmodel_name.py b/backend/product/migrations/0037_productdetailmodel_name.py new file mode 100644 index 0000000..c93a035 --- /dev/null +++ b/backend/product/migrations/0037_productdetailmodel_name.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1.2 on 2025-04-21 23:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0036_alter_productdetailmodel_detail_category'), + ] + + operations = [ + migrations.AddField( + model_name='productdetailmodel', + name='name', + field=models.CharField(default=1, help_text='این متن فقط برای راحتی در استفاده از پنل ادمین میباشد', max_length=50, verbose_name='نام جزيیات'), + preserve_default=False, + ), + ] diff --git a/backend/product/models.py b/backend/product/models.py index e3459e7..1a87333 100644 --- a/backend/product/models.py +++ b/backend/product/models.py @@ -213,6 +213,7 @@ class ProductImageModel(models.Model): class ProductDetailModel(models.Model): + name = models.CharField(max_length=50, verbose_name='نام جزيیات', help_text='این متن فقط برای راحتی در استفاده از پنل ادمین میباشد') detail_category = models.ForeignKey(ProductDetailCategory, on_delete=models.CASCADE, verbose_name='دسته بندی جزيات') detail = models.ManyToManyField(DetailModel, verbose_name='جزيات ها') @@ -220,7 +221,7 @@ class ProductDetailModel(models.Model): verbose_name = 'جزیات محصول' verbose_name_plural = 'جزیات محصول ها' def __str__(self): - return f'جزيیات محصول {self.detail_category.title}' + return f'جزيیات محصول {self.detail_category.title} - {self.name}' class ProductVariant(models.Model): product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='variants', verbose_name='محصول')