From 91f85b1a44fa6e652c5ecb8286b8f4f735417ad8 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Wed, 12 Feb 2025 18:32:31 +0330 Subject: [PATCH 1/3] add is main field to user address --- backend/account/admin.py | 2 +- .../0010_useraddressmodel_is_main.py | 18 ++++++++++++++++++ backend/account/models.py | 1 + backend/account/serializers.py | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 backend/account/migrations/0010_useraddressmodel_is_main.py diff --git a/backend/account/admin.py b/backend/account/admin.py index 07e62f7..e293140 100644 --- a/backend/account/admin.py +++ b/backend/account/admin.py @@ -72,7 +72,7 @@ class AddressAdmin(ModelAdmin, ImportExportModelAdmin): import_form_class = ImportForm export_form_class = ExportForm search_fields = ['address', 'name', 'city', 'province'] - list_display = ['user', 'name', 'address_display', 'postal_code', 'city', 'province', 'for_me'] + list_display = ['user', 'name', 'address_display', 'postal_code', 'city', 'province', 'for_me', 'is_main'] #readonly_fields = ['user', 'name', 'address', 'postal_code', 'phone', 'city', 'province', 'for_me'] compressed_fields = True warn_unsaved_form = True diff --git a/backend/account/migrations/0010_useraddressmodel_is_main.py b/backend/account/migrations/0010_useraddressmodel_is_main.py new file mode 100644 index 0000000..513e009 --- /dev/null +++ b/backend/account/migrations/0010_useraddressmodel_is_main.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.2 on 2025-02-12 15:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0009_alter_user_gender'), + ] + + operations = [ + migrations.AddField( + model_name='useraddressmodel', + name='is_main', + field=models.BooleanField(default=False), + ), + ] diff --git a/backend/account/models.py b/backend/account/models.py index 9038461..fc097df 100644 --- a/backend/account/models.py +++ b/backend/account/models.py @@ -127,6 +127,7 @@ class UserAddressModel(models.Model): city = models.CharField(max_length=30, verbose_name='شهر') province = models.CharField(max_length=30, verbose_name='استان') for_me = models.BooleanField(default=False, verbose_name='برای خود کاربر') + is_main = models.BooleanField(default=False) def __str__(self): return f"{self.user.phone}, {self.name}" diff --git a/backend/account/serializers.py b/backend/account/serializers.py index 0bb0e30..5c17c8f 100644 --- a/backend/account/serializers.py +++ b/backend/account/serializers.py @@ -17,7 +17,7 @@ class ProfileSerializer(serializers.ModelSerializer): class UserAddressSerializer(serializers.ModelSerializer): class Meta: model = UserAddressModel - fields = ['id', 'name', 'address', 'postal_code', 'phone', 'city', 'province', 'for_me'] + fields = ['id', 'name', 'address', 'postal_code', 'phone', 'city', 'province', 'for_me', 'is_main'] read_only_fields = ('id',) def validate(self, data): user = self.context['request'].user From 2de2fa130c7bbdc724f2d147c88843ff31c8baa2 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Wed, 12 Feb 2025 18:41:29 +0330 Subject: [PATCH 2/3] admin display image --- backend/product/admin.py | 38 +++++++++---------- ...lter_productimagemodel_options_and_more.py | 32 ++++++++++++++++ 2 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 backend/product/migrations/0023_alter_productimagemodel_options_and_more.py diff --git a/backend/product/admin.py b/backend/product/admin.py index 334e46f..67703d7 100644 --- a/backend/product/admin.py +++ b/backend/product/admin.py @@ -154,7 +154,7 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin): autocomplete_fields = ['related_products', ] # compressed_fields = True warn_unsaved_form = True - list_display = ['display_price', 'view', 'show', 'rating', 'category', ] + list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', ] fieldsets = ( ('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'related_products', 'show',), "classes": ["tab"],}), ('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}), @@ -176,24 +176,24 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin): return obj.get_toman_price() display_price.short_description = 'قیمت تومانی' - # @display(description='محصول', header=True) - # def display_image(self, instance): - # if instance and instance.variants.first() and instance.variants.first().attributes.first(): - # image = instance.variants.first().attributes.first().image.url if instance.variants.first().attributes.first().image else None - # else: - # image = None - # return [ - # instance.name, - # None, - # None, - # { - # "path": image, - # "height": 30, - # "width": 30, - # "borderless": True, - # # "squared": True, - # }, - # ] + @display(description='محصول', header=True) + def display_image(self, instance): + if instance and instance.variants.first() and instance.variants.first().images.first(): + image = instance.variants.first().images.first().image.url if instance.variants.first().images.first().image else None + else: + image = None + return [ + instance.name, + None, + None, + { + "path": image, + "height": 30, + "width": 30, + "borderless": True, + # "squared": True, + }, + ] # @display( # description=("نمایش در صفحه ی اصلی"), # label={ diff --git a/backend/product/migrations/0023_alter_productimagemodel_options_and_more.py b/backend/product/migrations/0023_alter_productimagemodel_options_and_more.py new file mode 100644 index 0000000..8a760ac --- /dev/null +++ b/backend/product/migrations/0023_alter_productimagemodel_options_and_more.py @@ -0,0 +1,32 @@ +# Generated by Django 5.1.2 on 2025-02-12 15:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0022_productimagemodel_remove_attributevalue_color_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='productimagemodel', + options={'verbose_name': 'عکس محصولات', 'verbose_name_plural': 'عکس های محصولات'}, + ), + migrations.AlterField( + model_name='detailmodel', + name='detail_text2', + field=models.CharField(blank=True, max_length=150, null=True, verbose_name='متن جزیات ۲'), + ), + migrations.AlterField( + model_name='detailmodel', + name='detail_text3', + field=models.CharField(blank=True, max_length=150, null=True, verbose_name='متن جزیات ۳'), + ), + migrations.AlterField( + model_name='detailmodel', + name='detail_text4', + field=models.CharField(blank=True, max_length=150, null=True, verbose_name='متن جزیات ۴'), + ), + ] From 9cdd903eac7751dbc36de07d4b66082d7c25874e Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Wed, 12 Feb 2025 18:45:15 +0330 Subject: [PATCH 3/3] add price cuaclate for admin pannel --- backend/product/admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/product/admin.py b/backend/product/admin.py index 67703d7..43b905d 100644 --- a/backend/product/admin.py +++ b/backend/product/admin.py @@ -172,8 +172,8 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin): } def display_price(self, obj): - return 1000 - return obj.get_toman_price() + if obj.variants.all().first(): + return obj.variants.all().first().get_toman_price() display_price.short_description = 'قیمت تومانی' @display(description='محصول', header=True)