From 6524ae7605642d6dfdf2276ea7f06df8ab4e9c3b Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Wed, 29 Oct 2025 21:05:56 +0330 Subject: [PATCH] add image filed to product --- backend/product/admin.py | 2 +- .../migrations/0056_productmodel_image.py | 19 +++++++++++++++++++ backend/product/models.py | 1 + backend/product/serializers.py | 8 ++++---- 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 backend/product/migrations/0056_productmodel_image.py diff --git a/backend/product/admin.py b/backend/product/admin.py index a69dc5d..31c4ee8 100644 --- a/backend/product/admin.py +++ b/backend/product/admin.py @@ -219,7 +219,7 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin): actions_list = ['redirect_to_learn', 'update_products_price'] list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', 'created_at'] fieldsets = ( - ('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'related_products', 'show', 'shop', 'show_in_bot', 'bot_banner'), "classes": ["tab"],}), + ('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'image', 'related_products', 'show', 'shop', 'show_in_bot', 'bot_banner'), "classes": ["tab"],}), ('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}), ('فیلد های مربوط به کاربر', {'fields': ('rating', 'view',), "classes": ["tab"],}), # ('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],}) diff --git a/backend/product/migrations/0056_productmodel_image.py b/backend/product/migrations/0056_productmodel_image.py new file mode 100644 index 0000000..e94c109 --- /dev/null +++ b/backend/product/migrations/0056_productmodel_image.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1.2 on 2025-10-29 16:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0055_alter_productmodel_options'), + ] + + operations = [ + migrations.AddField( + model_name='productmodel', + name='image', + field=models.ImageField(default='', upload_to='product_main/'), + preserve_default=False, + ), + ] diff --git a/backend/product/models.py b/backend/product/models.py index da0ed8c..ed02b99 100644 --- a/backend/product/models.py +++ b/backend/product/models.py @@ -111,6 +111,7 @@ class InPackItems(models.Model): class ProductModel(models.Model): name = models.CharField(max_length=255, verbose_name='نام') description = models.TextField(verbose_name='توضیحات') + image = models.ImageField(upload_to='product_main/') rating = models.PositiveIntegerField(default=0, verbose_name='امتیاز') show = models.BooleanField(default=False, verbose_name='نمایش در خانه') view = models.IntegerField(default=0, verbose_name='بازدید') diff --git a/backend/product/serializers.py b/backend/product/serializers.py index 8fbfe20..4faf06d 100644 --- a/backend/product/serializers.py +++ b/backend/product/serializers.py @@ -130,10 +130,10 @@ class DynamicProductSerializer(serializers.ModelSerializer): model = ProductModel fields = "__all__" view_type = { - 'list': ['id','name', 'rating', 'slug', 'category', 'variants', 'colors'], - 'slider': ['id','name', 'rating', 'slug', 'category', 'variants', 'colors'], - 'instance': ['id', 'name', 'description', 'rating', 'slug', 'meta_description', 'meta_keywords', 'meta_rating', 'category', 'related_products', 'in_pack_items', 'variants', 'colors', 'added_to_favorites'], - 'chat': ['id', 'name', 'description', 'variants'] + 'list': ['id','name', 'rating', 'slug', 'category', 'variants', 'colors', 'image'], + 'slider': ['id','name', 'rating', 'slug', 'category', 'variants', 'colors', 'image'], + 'instance': ['id', 'name', 'description', 'rating', 'slug', 'meta_description', 'meta_keywords', 'meta_rating', 'category', 'related_products', 'in_pack_items', 'variants', 'colors', 'added_to_favorites', 'image'], + 'chat': ['id', 'name', 'description', 'variants', 'image'] } def get_added_to_favorites(self, obj):