diff --git a/config/settings/common.py b/config/settings/common.py index c4ebafd..a42c67a 100644 --- a/config/settings/common.py +++ b/config/settings/common.py @@ -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)] diff --git a/core/apps/api/filters/products.py b/core/apps/api/filters/products.py index 49da28b..f6a65e9 100644 --- a/core/apps/api/filters/products.py +++ b/core/apps/api/filters/products.py @@ -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", ] diff --git a/core/apps/api/migrations/0007_productsmodel_description.py b/core/apps/api/migrations/0007_productsmodel_description.py new file mode 100644 index 0000000..4ad252c --- /dev/null +++ b/core/apps/api/migrations/0007_productsmodel_description.py @@ -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'), + ), + ] diff --git a/core/apps/api/migrations/0008_subproductmodel_description.py b/core/apps/api/migrations/0008_subproductmodel_description.py new file mode 100644 index 0000000..dc15966 --- /dev/null +++ b/core/apps/api/migrations/0008_subproductmodel_description.py @@ -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'), + ), + ] diff --git a/core/apps/api/models/products.py b/core/apps/api/models/products.py index 6720980..a46cd8f 100644 --- a/core/apps/api/models/products.py +++ b/core/apps/api/models/products.py @@ -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}" diff --git a/core/apps/api/serializers/products/products.py b/core/apps/api/serializers/products/products.py index ef04b27..0d570f7 100644 --- a/core/apps/api/serializers/products/products.py +++ b/core/apps/api/serializers/products/products.py @@ -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", ]