delete mathod qoshildi

This commit is contained in:
Husanjonazamov
2026-03-31 14:00:42 +05:00
parent 6f279fcb7d
commit cf23a61b98
6 changed files with 54 additions and 0 deletions

View File

@@ -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",
]

View 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'),
),
]

View 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'),
),
]

View File

@@ -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}"

View File

@@ -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",
]