delete mathod qoshildi
This commit is contained in:
@@ -49,6 +49,7 @@ INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django.contrib.postgres",
|
||||
] + APPS
|
||||
|
||||
MODULES = [app for app in MODULES if isinstance(app, str)]
|
||||
|
||||
@@ -6,6 +6,7 @@ from core.apps.api.models import ProductsModel, SubProductModel
|
||||
class ProductsFilter(filters.FilterSet):
|
||||
category = filters.NumberFilter(field_name="subcategory__category_id")
|
||||
filial = filters.NumberFilter(field_name="subcategory__category__filial_id")
|
||||
category_type = filters.CharFilter(field_name="subcategory__category__type")
|
||||
|
||||
class Meta:
|
||||
model = ProductsModel
|
||||
@@ -14,13 +15,17 @@ class ProductsFilter(filters.FilterSet):
|
||||
"subcategory",
|
||||
"category",
|
||||
"filial",
|
||||
"category_type",
|
||||
]
|
||||
|
||||
|
||||
class SubProductFilter(filters.FilterSet):
|
||||
category_type = filters.CharFilter(field_name="product__subcategory__category__type")
|
||||
|
||||
class Meta:
|
||||
model = SubProductModel
|
||||
fields = [
|
||||
"product",
|
||||
"name",
|
||||
"category_type",
|
||||
]
|
||||
|
||||
18
core/apps/api/migrations/0007_productsmodel_description.py
Normal file
18
core/apps/api/migrations/0007_productsmodel_description.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.7 on 2026-03-31 08:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0006_alter_categorymodel_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='productsmodel',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='description'),
|
||||
),
|
||||
]
|
||||
18
core/apps/api/migrations/0008_subproductmodel_description.py
Normal file
18
core/apps/api/migrations/0008_subproductmodel_description.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.7 on 2026-03-31 08:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0007_productsmodel_description'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='subproductmodel',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='description'),
|
||||
),
|
||||
]
|
||||
@@ -17,6 +17,7 @@ class ProductsModel(AbstractBaseModel):
|
||||
related_name="products",
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
description = models.TextField(verbose_name=_("description"), null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -41,6 +42,7 @@ class SubProductModel(AbstractBaseModel):
|
||||
name = models.CharField(verbose_name=_("name"), max_length=255)
|
||||
price = models.DecimalField(verbose_name=_("price"), max_digits=10, decimal_places=2, default=0.0)
|
||||
image = models.ImageField(verbose_name=_("image"), upload_to="subproducts/", null=True, blank=True)
|
||||
description = models.TextField(verbose_name=_("description"), null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.product.name} - {self.name}"
|
||||
|
||||
@@ -4,11 +4,15 @@ from core.apps.api.models import ProductsModel, SubProductModel
|
||||
|
||||
|
||||
class SubProductSerializer(serializers.ModelSerializer):
|
||||
type = serializers.CharField(source="product.subcategory.category.type", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = SubProductModel
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"type",
|
||||
"price",
|
||||
"image",
|
||||
]
|
||||
@@ -16,12 +20,15 @@ class SubProductSerializer(serializers.ModelSerializer):
|
||||
|
||||
class BaseProductsSerializer(serializers.ModelSerializer):
|
||||
subproducts = SubProductSerializer(many=True, read_only=True)
|
||||
type = serializers.CharField(source="subcategory.category.type", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = ProductsModel
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"type",
|
||||
"price",
|
||||
"image",
|
||||
"subcategory",
|
||||
@@ -34,6 +41,8 @@ class ListProductsSerializer(BaseProductsSerializer):
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"type",
|
||||
"price",
|
||||
"image",
|
||||
"subcategory",
|
||||
@@ -50,6 +59,7 @@ class CreateProductsSerializer(BaseProductsSerializer):
|
||||
"id",
|
||||
"subcategory",
|
||||
"name",
|
||||
"description",
|
||||
"price",
|
||||
"image",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user