fix es for establishments
This commit is contained in:
parent
bebd1283c0
commit
1d9ee76a5c
|
|
@ -56,7 +56,4 @@ class GuideSerializer(serializers.ModelSerializer):
|
|||
'name',
|
||||
'start',
|
||||
'end',
|
||||
'parent',
|
||||
'advertorials',
|
||||
'collection'
|
||||
]
|
||||
|
|
|
|||
|
|
@ -62,8 +62,9 @@ class ProductBackOfficeDetailSerializer(ProductDetailSerializer):
|
|||
'available',
|
||||
'product_type',
|
||||
'establishment',
|
||||
'wine_region',
|
||||
'wine_sub_region',
|
||||
# todo: need fix
|
||||
# 'wine_region',
|
||||
# 'wine_sub_region',
|
||||
'wine_village',
|
||||
'state',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -83,33 +83,59 @@ class EstablishmentDocument(Document):
|
|||
multi=True)
|
||||
products = fields.ObjectField(
|
||||
properties={
|
||||
'wine_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
# 'coordinates': fields.GeoPointField(),
|
||||
'description': fields.ObjectField(attr='description_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
}),
|
||||
'wine_origins': fields.ListField(
|
||||
fields.ObjectField(
|
||||
properties={
|
||||
'wine_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
# 'coordinates': fields.GeoPointField(),
|
||||
'description': fields.ObjectField(attr='description_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
|
||||
}),
|
||||
'wine_sub_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
}),
|
||||
})),
|
||||
'wine_colors': fields.ObjectField(
|
||||
properties={
|
||||
'id': fields.IntegerField(),
|
||||
'label': fields.ObjectField(attr='label_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
'value': fields.KeywordField(),
|
||||
},
|
||||
multi=True,
|
||||
),
|
||||
'wine_sub_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
}),
|
||||
},
|
||||
multi=True,)},
|
||||
multi=True
|
||||
)
|
||||
wine_origins = fields.ListField(
|
||||
fields.ObjectField(
|
||||
properties={
|
||||
'wine_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
# 'coordinates': fields.GeoPointField(),
|
||||
'description': fields.ObjectField(attr='description_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
|
||||
}),
|
||||
'wine_sub_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
})})
|
||||
)
|
||||
schedule = fields.ListField(fields.ObjectField(
|
||||
properties={
|
||||
'id': fields.IntegerField(attr='id'),
|
||||
|
|
|
|||
|
|
@ -83,22 +83,28 @@ class ProductDocument(Document):
|
|||
},
|
||||
multi=True,
|
||||
)
|
||||
wine_region = fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
# 'coordinates': fields.GeoPointField(),
|
||||
'description': fields.ObjectField(attr='description_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
})
|
||||
wine_sub_region = fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
})
|
||||
wine_origins = fields.ListField(
|
||||
fields.ObjectField(
|
||||
properties={
|
||||
'wine_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
# 'coordinates': fields.GeoPointField(),
|
||||
'description': fields.ObjectField(attr='description_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
|
||||
}),
|
||||
'wine_sub_region': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.KeywordField(),
|
||||
})})
|
||||
)
|
||||
classifications = fields.ObjectField( # TODO
|
||||
properties={
|
||||
'classification_type': fields.ObjectField(properties={}),
|
||||
|
|
|
|||
|
|
@ -69,6 +69,16 @@ class WineRegionDocumentSerializer(serializers.Serializer):
|
|||
return instance.wine_region if instance and instance.wine_region else None
|
||||
|
||||
|
||||
class WineSubRegionDocumentSerializer(serializers.Serializer):
|
||||
"""Wine region ES document serializer."""
|
||||
|
||||
id = serializers.IntegerField()
|
||||
name = serializers.CharField()
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance.wine_sub_region if instance and instance.wine_sub_region else None
|
||||
|
||||
|
||||
class TagDocumentSerializer(serializers.Serializer):
|
||||
"""Tag ES document serializer,"""
|
||||
|
||||
|
|
@ -223,6 +233,13 @@ class NewsDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
return get_translated_value(obj.subtitle)
|
||||
|
||||
|
||||
class WineOriginSerializer(serializers.Serializer):
|
||||
"""Wine origin serializer."""
|
||||
|
||||
wine_region = WineRegionDocumentSerializer()
|
||||
wine_sub_region = WineSubRegionDocumentSerializer(allow_null=True)
|
||||
|
||||
|
||||
class EstablishmentDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
||||
"""Establishment document serializer."""
|
||||
|
||||
|
|
@ -234,6 +251,7 @@ class EstablishmentDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
restaurant_cuisine = TagsDocumentSerializer(many=True, allow_null=True)
|
||||
artisan_category = TagsDocumentSerializer(many=True, allow_null=True)
|
||||
schedule = ScheduleDocumentSerializer(many=True, allow_null=True)
|
||||
wine_origins = WineOriginSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
|
@ -259,6 +277,7 @@ class EstablishmentDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
'works_evening',
|
||||
'works_at_weekday',
|
||||
'tz',
|
||||
'wine_origins',
|
||||
# 'works_now',
|
||||
# 'collections',
|
||||
# 'establishment_type',
|
||||
|
|
@ -276,6 +295,7 @@ class ProductDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
grape_variety = TagDocumentSerializer(many=True)
|
||||
product_type = ProductTypeDocumentSerializer(allow_null=True)
|
||||
establishment_detail = ProductEstablishmentDocumentSerializer(source='establishment', allow_null=True)
|
||||
wine_origins = WineOriginSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
|
@ -302,4 +322,5 @@ class ProductDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
'establishment_detail',
|
||||
'average_price',
|
||||
'created',
|
||||
'wine_origins',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -158,7 +158,15 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
|||
},
|
||||
},
|
||||
'wine_region_id': {
|
||||
'field': 'products.wine_region.id',
|
||||
'field': 'wine_origins.wine_region.id',
|
||||
'facet': TermsFacet,
|
||||
'enabled': True,
|
||||
'options': {
|
||||
'size': utils.FACET_MAX_RESPONSE,
|
||||
},
|
||||
},
|
||||
'wine_sub_region_id': {
|
||||
'field': 'wine_origins.wine_sub_region.id',
|
||||
'facet': TermsFacet,
|
||||
'enabled': True,
|
||||
'options': {
|
||||
|
|
@ -213,14 +221,14 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
|||
],
|
||||
},
|
||||
'wine_region_id': {
|
||||
'field': 'products.wine_region.id',
|
||||
'field': 'wine_origins.wine_region.id',
|
||||
'lookups': [
|
||||
constants.LOOKUP_QUERY_IN,
|
||||
constants.LOOKUP_QUERY_EXCLUDE,
|
||||
],
|
||||
},
|
||||
'wine_sub_region_id': {
|
||||
'field': 'products.wine_sub_region_id',
|
||||
'field': 'wine_origins.wine_sub_region.id',
|
||||
'lookups': [
|
||||
constants.LOOKUP_QUERY_IN,
|
||||
constants.LOOKUP_QUERY_EXCLUDE,
|
||||
|
|
@ -354,13 +362,21 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
|||
},
|
||||
},
|
||||
'wine_region_id': {
|
||||
'field': 'wine_region.id',
|
||||
'enabled': True,
|
||||
'field': 'wine_origins.wine_region.id',
|
||||
'facet': TermsFacet,
|
||||
'enabled': True,
|
||||
'options': {
|
||||
'size': utils.FACET_MAX_RESPONSE,
|
||||
},
|
||||
},
|
||||
'wine_sub_region_id': {
|
||||
'field': 'wine_origins.wine_sub_region.id',
|
||||
'facet': TermsFacet,
|
||||
'enabled': True,
|
||||
'options': {
|
||||
'size': utils.FACET_MAX_RESPONSE,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
translated_search_fields = (
|
||||
|
|
@ -384,14 +400,14 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
|||
],
|
||||
},
|
||||
'wine_region_id': {
|
||||
'field': 'wine_region.id',
|
||||
'field': 'wine_origins.wine_region.id',
|
||||
'lookups': [
|
||||
constants.LOOKUP_QUERY_IN,
|
||||
constants.LOOKUP_QUERY_EXCLUDE,
|
||||
],
|
||||
},
|
||||
'wine_sub_region_id': {
|
||||
'field': 'wine_sub_region_id',
|
||||
'field': 'wine_origins.wine_sub_region.id',
|
||||
'lookups': [
|
||||
constants.LOOKUP_QUERY_IN,
|
||||
constants.LOOKUP_QUERY_EXCLUDE,
|
||||
|
|
@ -404,9 +420,9 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
|||
constants.LOOKUP_QUERY_EXCLUDE,
|
||||
]
|
||||
},
|
||||
'wine_from_country_code': {
|
||||
'field': 'wine_region.country.code',
|
||||
},
|
||||
# 'wine_from_country_code': {
|
||||
# 'field': 'wine_origins.wine_region.country.code',
|
||||
# },
|
||||
'for_establishment': {
|
||||
'field': 'establishment.slug',
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user