This commit is contained in:
Mamalizz
2025-02-14 01:28:32 +03:30
6 changed files with 74 additions and 23 deletions
+1 -1
View File
@@ -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
@@ -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),
),
]
+1
View File
@@ -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}"
+1 -1
View File
@@ -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
+21 -21
View File
@@ -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"],}),
@@ -172,28 +172,28 @@ 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)
# 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={
@@ -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='متن جزیات ۴'),
),
]