Fix product type serializer
This commit is contained in:
parent
dc10203f8a
commit
ca61359a81
|
|
@ -79,6 +79,18 @@ class WineColorDocumentSerializer(serializers.Serializer):
|
||||||
return get_translated_value(obj.label)
|
return get_translated_value(obj.label)
|
||||||
|
|
||||||
|
|
||||||
|
class ProductTypeDocumentSerializer(serializers.Serializer):
|
||||||
|
"""Product type ES document serializer."""
|
||||||
|
|
||||||
|
id = serializers.IntegerField()
|
||||||
|
index_name = serializers.CharField()
|
||||||
|
name_translated = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_name_translated(obj):
|
||||||
|
return get_translated_value(obj.name)
|
||||||
|
|
||||||
|
|
||||||
class ProductEstablishmentDocumentSerializer(serializers.Serializer):
|
class ProductEstablishmentDocumentSerializer(serializers.Serializer):
|
||||||
"""Related to Product Establishment ES document serializer."""
|
"""Related to Product Establishment ES document serializer."""
|
||||||
|
|
||||||
|
|
@ -202,13 +214,9 @@ class ProductDocumentSerializer(DocumentSerializer):
|
||||||
subtypes = ProductSubtypeDocumentSerializer(many=True)
|
subtypes = ProductSubtypeDocumentSerializer(many=True)
|
||||||
wine_region = WineRegionDocumentSerializer(allow_null=True)
|
wine_region = WineRegionDocumentSerializer(allow_null=True)
|
||||||
wine_colors = WineColorDocumentSerializer(many=True)
|
wine_colors = WineColorDocumentSerializer(many=True)
|
||||||
product_type = serializers.SerializerMethodField()
|
product_type = ProductTypeDocumentSerializer(allow_null=True)
|
||||||
establishment_detail = ProductEstablishmentDocumentSerializer(source='establishment', allow_null=True)
|
establishment_detail = ProductEstablishmentDocumentSerializer(source='establishment', allow_null=True)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_product_type(obj):
|
|
||||||
return get_translated_value(obj.product_type.name if obj.product_type else {})
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -251,6 +251,9 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
||||||
'type': {
|
'type': {
|
||||||
'field': 'product_type.index_name',
|
'field': 'product_type.index_name',
|
||||||
},
|
},
|
||||||
|
'product_type': {
|
||||||
|
'field': 'product_type.index_name',
|
||||||
|
},
|
||||||
'subtype': {
|
'subtype': {
|
||||||
'field': 'subtypes.index_name',
|
'field': 'subtypes.index_name',
|
||||||
'lookups': [
|
'lookups': [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user