new sliders add for home page
This commit is contained in:
+16
-3
@@ -27,8 +27,17 @@ class HomeView(APIView):
|
|||||||
main_categories = MainCategoryModel.objects.filter(show_in_home=True)
|
main_categories = MainCategoryModel.objects.filter(show_in_home=True)
|
||||||
main_category_ser = MainCategorySerializer(instance=main_categories, many=True, context={'request': request})
|
main_category_ser = MainCategorySerializer(instance=main_categories, many=True, context={'request': request})
|
||||||
|
|
||||||
products_to_show = ProductModel.objects.filter(show=True)
|
top_seller_products = ProductModel.objects.filter(show_in_top_seller=True)
|
||||||
product_ser = DynamicProductSerializer(instance=products_to_show, many=True, context={'request': request, 'view_type': 'list'})
|
top_seller_products_ser = DynamicProductSerializer(instance=top_seller_products, many=True, context={'request': request, 'view_type': 'list'})
|
||||||
|
|
||||||
|
lot_of_discount_products = ProductModel.objects.filter(show_in_lot_of_discount=True)
|
||||||
|
lot_of_discount_products_ser = DynamicProductSerializer(instance=lot_of_discount_products, many=True, context={'request': request, 'view_type': 'list'})
|
||||||
|
|
||||||
|
most_viewed_products = ProductModel.objects.filter(show_in_most_viewed=True)
|
||||||
|
most_viewed_products_ser = DynamicProductSerializer(instance=most_viewed_products, many=True, context={'request': request, 'view_type': 'list'})
|
||||||
|
|
||||||
|
trends_products = ProductModel.objects.filter(show_in_trends=True)
|
||||||
|
trends_products_ser = DynamicProductSerializer(instance=trends_products, many=True, context={'request': request, 'view_type': 'list'})
|
||||||
|
|
||||||
home_image = HomeImageModel.objects.all().first()
|
home_image = HomeImageModel.objects.all().first()
|
||||||
home_image_ser = HomeImageSerializer(instance=home_image, context={'request': request})
|
home_image_ser = HomeImageSerializer(instance=home_image, context={'request': request})
|
||||||
@@ -39,7 +48,11 @@ class HomeView(APIView):
|
|||||||
response = {
|
response = {
|
||||||
'sliders': slider_ser.data,
|
'sliders': slider_ser.data,
|
||||||
'main_categories': main_category_ser.data,
|
'main_categories': main_category_ser.data,
|
||||||
'products': product_ser.data,
|
'products': [],
|
||||||
|
'top_seller_products': top_seller_products_ser.data,
|
||||||
|
'lot_of_discount_products': lot_of_discount_products_ser.data,
|
||||||
|
'most_viewed_products': most_viewed_products_ser.data,
|
||||||
|
'trends_products': trends_products_ser.data,
|
||||||
'difreance_section': home_image_ser.data,
|
'difreance_section': home_image_ser.data,
|
||||||
'show_case_slider': show_cases_ser.data
|
'show_case_slider': show_cases_ser.data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,16 +295,16 @@ class ProductModelAdmin(ProductAdminPermission, ModelAdmin, ImportExportModelAdm
|
|||||||
inlines = [ProductVariantInLine]
|
inlines = [ProductVariantInLine]
|
||||||
readonly_fields = ('slug', 'created_at')
|
readonly_fields = ('slug', 'created_at')
|
||||||
search_fields = ['name', 'description', ]
|
search_fields = ['name', 'description', ]
|
||||||
list_filter = ['show', ('category', RelatedDropdownFilter), 'show_in_bot', ('category__parent', RelatedDropdownFilter)]
|
list_filter = [('category', RelatedDropdownFilter), 'show_in_bot', ('category__parent', RelatedDropdownFilter)]
|
||||||
list_filter_submit = True
|
list_filter_submit = True
|
||||||
autocomplete_fields = ['related_products', 'shop', 'category']
|
autocomplete_fields = ['related_products', 'shop', 'category']
|
||||||
# compressed_fields = True
|
# compressed_fields = True
|
||||||
warn_unsaved_form = True
|
warn_unsaved_form = True
|
||||||
# list_per_page = 2
|
# list_per_page = 2
|
||||||
actions_list = ['redirect_to_learn', 'update_products_price']
|
actions_list = ['redirect_to_learn', 'update_products_price']
|
||||||
list_display = ['display_image', 'shop__shop_name','display_price', 'view', 'show', 'rating', 'category', 'created_at']
|
list_display = ['display_image', 'shop__shop_name','display_price', 'view', 'rating', 'category', 'created_at']
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'image', 'related_products', 'show', 'shop', 'show_in_bot', 'bot_banner'), "classes": ["tab"],}),
|
('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'image', 'related_products','show_in_trends', 'show_in_most_viewed', 'show_in_lot_of_discount', 'show_in_top_seller', 'shop', 'show_in_bot', 'bot_banner'), "classes": ["tab"],}),
|
||||||
('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}),
|
('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}),
|
||||||
('فیلد های مربوط به کاربر', {'fields': ('rating', 'view',), "classes": ["tab"],}),
|
('فیلد های مربوط به کاربر', {'fields': ('rating', 'view',), "classes": ["tab"],}),
|
||||||
# ('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],})
|
# ('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],})
|
||||||
@@ -324,7 +324,7 @@ class ProductModelAdmin(ProductAdminPermission, ModelAdmin, ImportExportModelAdm
|
|||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
return ['slug', 'created_at']
|
return ['slug', 'created_at']
|
||||||
else:
|
else:
|
||||||
return ['show_in_bot', 'bot_banner', 'created_at', 'show', 'meta_description', 'meta_keywords', 'meta_rating', 'rating', 'view', 'slug']
|
return ['show_in_bot', 'bot_banner', 'created_at', 'show_in_top_seller','show_in_trends', 'show_in_most_viewed', 'show_in_lot_of_discount','meta_description', 'meta_keywords', 'meta_rating', 'rating', 'view', 'slug']
|
||||||
|
|
||||||
def display_price(self, obj):
|
def display_price(self, obj):
|
||||||
if obj.variants.all().first():
|
if obj.variants.all().first():
|
||||||
@@ -398,15 +398,6 @@ class ProductModelAdmin(ProductAdminPermission, ModelAdmin, ImportExportModelAdm
|
|||||||
actions = ['bulk_update_subcategory_action']
|
actions = ['bulk_update_subcategory_action']
|
||||||
|
|
||||||
|
|
||||||
# @display(
|
|
||||||
# description=("نمایش در صفحه ی اصلی"),
|
|
||||||
# label={
|
|
||||||
# True: "danger",
|
|
||||||
# False: "success",
|
|
||||||
# },
|
|
||||||
# )
|
|
||||||
# def display_show(self, instance):
|
|
||||||
# return instance.show
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(MainCategoryModel)
|
@admin.register(MainCategoryModel)
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# Generated by Django 5.1.2 on 2026-02-20 15:39
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('account', '0034_add_telegram_chat_id_to_shop'),
|
||||||
|
('product', '0071_maincategorymodel_show_in_home'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveIndex(
|
||||||
|
model_name='productmodel',
|
||||||
|
name='product_show_idx',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='productmodel',
|
||||||
|
name='show',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='productmodel',
|
||||||
|
name='show_in_lot_of_discount',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='نمایش در پر تخفیف ها'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='productmodel',
|
||||||
|
name='show_in_most_viewed',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='نمایش در پر بازدید ها'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='productmodel',
|
||||||
|
name='show_in_top_seller',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='نمایش در پر فروش ها'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='productmodel',
|
||||||
|
name='show_in_trends',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='نمایش در ترند ها'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='productmodel',
|
||||||
|
index=models.Index(fields=['show_in_trends'], name='product_show_in_trends_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='productmodel',
|
||||||
|
index=models.Index(fields=['show_in_most_viewed'], name='product_most_viewed_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='productmodel',
|
||||||
|
index=models.Index(fields=['show_in_lot_of_discount'], name='product_lot_of_discount_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='productmodel',
|
||||||
|
index=models.Index(fields=['show_in_top_seller'], name='product_show_in_top_seller_idx'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -181,7 +181,10 @@ class ProductModel(models.Model):
|
|||||||
description = models.TextField(verbose_name='توضیحات')
|
description = models.TextField(verbose_name='توضیحات')
|
||||||
image = models.ImageField(upload_to='product_main/', null=True, blank=True)
|
image = models.ImageField(upload_to='product_main/', null=True, blank=True)
|
||||||
rating = models.PositiveIntegerField(default=0, verbose_name='امتیاز')
|
rating = models.PositiveIntegerField(default=0, verbose_name='امتیاز')
|
||||||
show = models.BooleanField(default=False, verbose_name='نمایش در خانه')
|
show_in_trends = models.BooleanField(default=False, verbose_name='نمایش در ترند ها')
|
||||||
|
show_in_most_viewed = models.BooleanField(default=False, verbose_name='نمایش در پر بازدید ها')
|
||||||
|
show_in_lot_of_discount = models.BooleanField(default=False, verbose_name='نمایش در پر تخفیف ها')
|
||||||
|
show_in_top_seller = models.BooleanField(default=False, verbose_name='نمایش در پر فروش ها')
|
||||||
view = models.IntegerField(default=0, verbose_name='بازدید')
|
view = models.IntegerField(default=0, verbose_name='بازدید')
|
||||||
slug = models.SlugField(max_length=255, unique=True, blank=True, null=True, allow_unicode=True,
|
slug = models.SlugField(max_length=255, unique=True, blank=True, null=True, allow_unicode=True,
|
||||||
verbose_name='نام یکتا', help_text="این فیلد را خالی بگذارید")
|
verbose_name='نام یکتا', help_text="این فیلد را خالی بگذارید")
|
||||||
@@ -224,7 +227,10 @@ class ProductModel(models.Model):
|
|||||||
models.Index(fields=['category'], name='product_category_idx'),
|
models.Index(fields=['category'], name='product_category_idx'),
|
||||||
models.Index(fields=['name'], name='product_name_idx'),
|
models.Index(fields=['name'], name='product_name_idx'),
|
||||||
models.Index(fields=['created_at'], name='product_created_at_idx'),
|
models.Index(fields=['created_at'], name='product_created_at_idx'),
|
||||||
models.Index(fields=['show'], name='product_show_idx'),
|
models.Index(fields=['show_in_trends'], name='product_show_in_trends_idx'),
|
||||||
|
models.Index(fields=['show_in_most_viewed'], name='product_most_viewed_idx'),
|
||||||
|
models.Index(fields=['show_in_lot_of_discount'], name='product_lot_of_discount_idx'),
|
||||||
|
models.Index(fields=['show_in_top_seller'], name='product_show_in_top_seller_idx'),
|
||||||
models.Index(fields=['category', 'created_at'],
|
models.Index(fields=['category', 'created_at'],
|
||||||
name='product_category_created_idx'),
|
name='product_category_created_idx'),
|
||||||
models.Index(fields=['category', 'name'],
|
models.Index(fields=['category', 'name'],
|
||||||
|
|||||||
Reference in New Issue
Block a user