change bug of permissions list
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
from apps.product import models as product_models
|
||||
from apps.authorization.api.v1 import serializers as authorize_serializers
|
||||
|
||||
|
||||
class ReferenceProductSerializer(serializers.ModelSerializer):
|
||||
@@ -25,3 +26,77 @@ class ProductSerializer(serializers.ModelSerializer):
|
||||
representation['reference'] = ReferenceProductSerializer(instance.reference).data
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
class AttributeSerializer(serializers.ModelSerializer):
|
||||
""" serialize attributes of reference product """
|
||||
|
||||
class Meta:
|
||||
model = product_models.Attribute
|
||||
fields = '__all__'
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
if instance.reference_product:
|
||||
representation['reference_product'] = ReferenceProductSerializer(
|
||||
instance.reference_product
|
||||
).data
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
class AttributeValueSerializer(serializers.ModelSerializer):
|
||||
""" serialize attribute values for child products """
|
||||
|
||||
class Meta:
|
||||
model = product_models.AttributeValue
|
||||
fields = '__all__'
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom output """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
if instance.product:
|
||||
representation['product'] = ProductSerializer(instance.product).data
|
||||
if instance.attribute:
|
||||
representation['attribute'] = AttributeSerializer(instance.attribute).data
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
class BrokerSerializer(serializers.ModelSerializer):
|
||||
""" serialize product broker """
|
||||
|
||||
class Meta:
|
||||
model = product_models.Broker
|
||||
fields = '__all__'
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
if instance.reference_product:
|
||||
representation['reference_product'] = ReferenceProductSerializer(
|
||||
instance.reference_product
|
||||
).data
|
||||
if instance.organization_relations:
|
||||
representation['organization_relations'] = authorize_serializers.UserRelationSerializer(
|
||||
instance.organization_relations
|
||||
).data
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
class SaleUnitSerializer(serializers.ModelSerializer):
|
||||
""" serialize unit of products for sale """
|
||||
|
||||
class Meta:
|
||||
model = product_models.SaleUnit
|
||||
fields = '__all__'
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
if instance.reference_product:
|
||||
representation['reference_product'] = ReferenceProductSerializer(
|
||||
instance.reference_product
|
||||
).data
|
||||
|
||||
return representation
|
||||
|
||||
Reference in New Issue
Block a user