indexes of product

This commit is contained in:
Parsa Nazer
2025-07-28 15:25:37 +03:30
parent cf56b759bb
commit 996de7aab2
2 changed files with 201 additions and 1 deletions
@@ -0,0 +1,152 @@
# Generated by Django 5.1.2 on 2025-07-28 11:44
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0018_remove_showcaseslider_image_and_more'),
('product', '0049_alter_productmodel_slug'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['product'], name='comment_product_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['review_status'], name='comment_review_status_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['product', 'review_status'], name='comment_product_status_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['user'], name='comment_user_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['timestamp'], name='comment_timestamp_idx'),
),
migrations.AddIndex(
model_name='detailmodel',
index=models.Index(fields=['detail_model'], name='detail_model_idx'),
),
migrations.AddIndex(
model_name='detailmodel',
index=models.Index(fields=['title'], name='detail_title_idx'),
),
migrations.AddIndex(
model_name='dollormodel',
index=models.Index(fields=['unique_filed'], name='dollor_unique_field_idx'),
),
migrations.AddIndex(
model_name='maincategorymodel',
index=models.Index(fields=['slug'], name='main_category_slug_idx'),
),
migrations.AddIndex(
model_name='productdetailcategory',
index=models.Index(fields=['title'], name='detail_category_title_idx'),
),
migrations.AddIndex(
model_name='productdetailmodel',
index=models.Index(fields=['detail_category'], name='product_detail_category_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['slug'], name='product_slug_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['category'], name='product_category_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['name'], name='product_name_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['created_at'], name='product_created_at_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['show'], name='product_show_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['category', 'created_at'], name='product_category_created_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['category', 'name'], name='product_category_name_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product', 'price', 'created_at'], name='idx_product_price_created'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['in_stock', 'discount'], name='idx_stock_discount'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['created_at'], name='idx_created'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['price'], name='idx_price'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['discount'], name='product_variant_discount_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['in_stock'], name='product_variant_in_stock_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product'], name='product_variant_product_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category'], name='variant_slider_category_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category', 'in_stock'], name='variant_slider_stock_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category', 'discount'], name='variant_slider_discount_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category', 'created_at'], name='variant_slider_created_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product', 'in_stock'], name='variant_product_stock_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product', 'discount'], name='variant_product_discount_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['currency'], name='variant_currency_idx'),
),
migrations.AddIndex(
model_name='subcategorymodel',
index=models.Index(fields=['slug'], name='sub_category_slug_idx'),
),
migrations.AddIndex(
model_name='subcategorymodel',
index=models.Index(fields=['parent'], name='sub_category_parent_idx'),
),
]
+48
View File
@@ -17,6 +17,9 @@ class MainCategoryModel(models.Model):
class Meta: class Meta:
verbose_name = "دسته‌بندی اصلی" verbose_name = "دسته‌بندی اصلی"
verbose_name_plural = "دسته‌بندی‌هااصلی" verbose_name_plural = "دسته‌بندی‌هااصلی"
indexes = [
models.Index(fields=['slug'], name='main_category_slug_idx'),
]
def __str__(self): def __str__(self):
return self.name return self.name
@@ -39,6 +42,10 @@ class SubCategoryModel(models.Model):
class Meta: class Meta:
verbose_name = "زیر دسته‌بندی" verbose_name = "زیر دسته‌بندی"
verbose_name_plural = "زیر دسته‌بندی‌ها" verbose_name_plural = "زیر دسته‌بندی‌ها"
indexes = [
models.Index(fields=['slug'], name='sub_category_slug_idx'),
models.Index(fields=['parent'], name='sub_category_parent_idx'),
]
def __str__(self): def __str__(self):
return self.name return self.name
@@ -84,6 +91,9 @@ class DollorModel(models.Model):
class Meta: class Meta:
verbose_name = 'مدل دلار' verbose_name = 'مدل دلار'
verbose_name_plural = 'مدل دلار' verbose_name_plural = 'مدل دلار'
indexes = [
models.Index(fields=['unique_filed'], name='dollor_unique_field_idx'),
]
class InPackItems(models.Model): class InPackItems(models.Model):
@@ -127,6 +137,15 @@ class ProductModel(models.Model):
class Meta: class Meta:
verbose_name = 'محصول' verbose_name = 'محصول'
verbose_name_plural = 'محصولات' verbose_name_plural = 'محصولات'
indexes = [
models.Index(fields=['slug'], name='product_slug_idx'),
models.Index(fields=['category'], name='product_category_idx'),
models.Index(fields=['name'], name='product_name_idx'),
models.Index(fields=['created_at'], name='product_created_at_idx'),
models.Index(fields=['show'], name='product_show_idx'),
models.Index(fields=['category', 'created_at'], name='product_category_created_idx'),
models.Index(fields=['category', 'name'], name='product_category_name_idx'),
]
@@ -141,6 +160,9 @@ class ProductDetailCategory(models.Model):
class Meta: class Meta:
verbose_name = 'دسته بندی جزيات' verbose_name = 'دسته بندی جزيات'
verbose_name_plural = 'دسته بندی های جزيیات' verbose_name_plural = 'دسته بندی های جزيیات'
indexes = [
models.Index(fields=['title'], name='detail_category_title_idx'),
]
@@ -162,6 +184,13 @@ class CommentModel(models.Model):
class Meta: class Meta:
verbose_name = 'نظر' verbose_name = 'نظر'
verbose_name_plural = 'نظرات' verbose_name_plural = 'نظرات'
indexes = [
models.Index(fields=['product'], name='comment_product_idx'),
models.Index(fields=['review_status'], name='comment_review_status_idx'),
models.Index(fields=['product', 'review_status'], name='comment_product_status_idx'),
models.Index(fields=['user'], name='comment_user_idx'),
models.Index(fields=['timestamp'], name='comment_timestamp_idx'),
]
def __str__(self): def __str__(self):
return f"{self.user}-{self.content[:30]}" return f"{self.user}-{self.content[:30]}"
@@ -205,6 +234,9 @@ class ProductDetailModel(models.Model):
class Meta: class Meta:
verbose_name = 'جزیات محصول' verbose_name = 'جزیات محصول'
verbose_name_plural = 'جزیات محصول ها' verbose_name_plural = 'جزیات محصول ها'
indexes = [
models.Index(fields=['detail_category'], name='product_detail_category_idx'),
]
def __str__(self): def __str__(self):
return f'جزيیات محصول {self.detail_category.title} - {self.name}' return f'جزيیات محصول {self.detail_category.title} - {self.name}'
@@ -222,6 +254,10 @@ class DetailModel(models.Model):
class Meta: class Meta:
verbose_name = 'مدل جزیات' verbose_name = 'مدل جزیات'
verbose_name_plural = 'مدل های جزیات' verbose_name_plural = 'مدل های جزیات'
indexes = [
models.Index(fields=['detail_model'], name='detail_model_idx'),
models.Index(fields=['title'], name='detail_title_idx'),
]
class ProductVariant(models.Model): class ProductVariant(models.Model):
@@ -250,6 +286,18 @@ class ProductVariant(models.Model):
class Meta: class Meta:
verbose_name = 'تنوع محصول' verbose_name = 'تنوع محصول'
verbose_name_plural = 'تنوع‌های محصول' verbose_name_plural = 'تنوع‌های محصول'
indexes = [
# Existing indexes
models.Index(fields=['product', 'price', 'created_at'], name='idx_product_price_created'),
models.Index(fields=['in_stock', 'discount'], name='idx_stock_discount'),
models.Index(fields=['created_at'], name='idx_created'),
models.Index(fields=['price'], name='idx_price'),
models.Index(fields=['discount'], name='product_variant_discount_idx'),
models.Index(fields=['in_stock'], name='product_variant_in_stock_idx'),
models.Index(fields=['product'], name='product_variant_product_idx'),
models.Index(fields=['product', 'in_stock'], name='variant_product_stock_idx'),
models.Index(fields=['product', 'discount'], name='variant_product_discount_idx'),
]
def __str__(self): def __str__(self):
return f"{self.product.name} - {', '.join(str(attr) for attr in self.product_attributes.all())}" return f"{self.product.name} - {', '.join(str(attr) for attr in self.product_attributes.all())}"