#51 feat: serializadores de categorias y categorias anidadas en productos
Issue #51: discriminacion y administracion de categorias de productos. - ProductCategorySerializer (name/external_id read_only) - ProductCategoryBriefSerializer para el JSON de productos - ProductSerializer.categories ahora devuelve objetos anidados
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
from .catalogue_images import CatalogueImageSerializer
|
||||
from .products import ProductSerializer, ListProductSerializer
|
||||
from .products import (
|
||||
ProductSerializer,
|
||||
ListProductSerializer,
|
||||
ProductCategorySerializer,
|
||||
ProductCategoryBriefSerializer,
|
||||
)
|
||||
from .customers import CustomerSerializer, ListCustomerSerializer
|
||||
from .sales import (
|
||||
SaleSerializer,
|
||||
@@ -26,6 +31,8 @@ __all__ = [
|
||||
# Products
|
||||
"ProductSerializer",
|
||||
"ListProductSerializer",
|
||||
"ProductCategorySerializer",
|
||||
"ProductCategoryBriefSerializer",
|
||||
# Customers
|
||||
"CustomerSerializer",
|
||||
"ListCustomerSerializer",
|
||||
|
||||
@@ -4,11 +4,32 @@ from ..models.products import Product, ProductCategory
|
||||
from ..models.provenance import Supplier
|
||||
|
||||
|
||||
class ProductCategorySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductCategory
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"external_id",
|
||||
"description",
|
||||
"alternative_name",
|
||||
"active",
|
||||
]
|
||||
read_only_fields = ["name", "external_id"]
|
||||
|
||||
|
||||
class ProductCategoryBriefSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductCategory
|
||||
fields = ["id", "name", "alternative_name", "active"]
|
||||
|
||||
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
catalogue_images = serializers.SerializerMethodField()
|
||||
suppliers = serializers.PrimaryKeyRelatedField(
|
||||
many=True, queryset=Supplier.objects.all(), required=False
|
||||
)
|
||||
categories = ProductCategoryBriefSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
|
||||
Reference in New Issue
Block a user