diff --git a/backend/product/migrations/0010_alter_productmodel_related_products.py b/backend/product/migrations/0010_alter_productmodel_related_products.py new file mode 100644 index 0000000..a5abc36 --- /dev/null +++ b/backend/product/migrations/0010_alter_productmodel_related_products.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.2 on 2025-02-01 18:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0009_productmodel_related_products'), + ] + + operations = [ + migrations.AlterField( + model_name='productmodel', + name='related_products', + field=models.ManyToManyField(blank=True, null=True, to='product.productmodel'), + ), + ] diff --git a/backend/product/migrations/0011_alter_productmodel_category_and_more.py b/backend/product/migrations/0011_alter_productmodel_category_and_more.py new file mode 100644 index 0000000..af64444 --- /dev/null +++ b/backend/product/migrations/0011_alter_productmodel_category_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 5.1.2 on 2025-02-01 23:47 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0010_alter_productmodel_related_products'), + ] + + operations = [ + migrations.AlterField( + model_name='productmodel', + name='category', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='products', to='product.subcategorymodel', verbose_name='دسته بندی محصول'), + ), + migrations.AlterField( + model_name='productmodel', + name='related_products', + field=models.ManyToManyField(blank=True, to='product.productmodel'), + ), + ] diff --git a/backend/product/models.py b/backend/product/models.py index 5d62e7c..7381f6e 100644 --- a/backend/product/models.py +++ b/backend/product/models.py @@ -110,8 +110,8 @@ class ProductModel(models.Model): meta_keywords = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید') meta_rating = models.FloatField(default=5, help_text='امتیاز محصول') created_at = models.DateTimeField(auto_now_add=True, verbose_name='زمان ثبت محصول') - category = models.ForeignKey(SubCategoryModel, blank=True, null=True, on_delete=models.SET_NULL, related_name='products', verbose_name='دسته بندی محصول') - related_products = models.ManyToManyField('self',) + category = models.ForeignKey(SubCategoryModel, null=True, on_delete=models.SET_NULL, related_name='products', verbose_name='دسته بندی محصول') + related_products = models.ManyToManyField('self', blank=True,) def format_discount_price(self): discount_price = int(self.price * (100 - self.discount) / 100) formatted_num = "{:,.0f}".format(discount_price) @@ -156,7 +156,7 @@ class InStuckColors(models.Model): verbose_name = 'تعداد موجود رنگ' verbose_name_plural = 'تعداد موجود رنگ ها' def __str__(self): - return f'{product} - {color}' + return f'{self.product} - {self.color}' class CommentModel(models.Model): product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='comments', verbose_name='محصول')