product establishment_detail address
This commit is contained in:
parent
b5e1344b38
commit
41659958f7
|
|
@ -171,7 +171,7 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes,
|
|||
default=None, help_text='{"en-GB":"some text"}')
|
||||
available = models.BooleanField(_('available'), default=True)
|
||||
product_type = models.ForeignKey(ProductType, on_delete=models.PROTECT,
|
||||
null=True,
|
||||
null=True, blank=True, default=None,
|
||||
related_name='products', verbose_name=_('Type'))
|
||||
subtypes = models.ManyToManyField(ProductSubType, blank=True,
|
||||
related_name='products',
|
||||
|
|
|
|||
|
|
@ -14,12 +14,13 @@ class ProductDocument(Document):
|
|||
|
||||
description = fields.ObjectField(attr='description_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
product_type = fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
'index_name': fields.KeywordField(),
|
||||
'use_subtypes': fields.BooleanField(),
|
||||
})
|
||||
product_type = fields.ObjectField(
|
||||
properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
'index_name': fields.KeywordField(),
|
||||
}
|
||||
)
|
||||
subtypes = fields.ObjectField(
|
||||
properties={
|
||||
'id': fields.IntegerField(),
|
||||
|
|
@ -54,15 +55,12 @@ class ProductDocument(Document):
|
|||
),
|
||||
'address': fields.ObjectField(
|
||||
properties={
|
||||
'city': fields.ObjectField(
|
||||
properties={
|
||||
'country': fields.ObjectField(
|
||||
properties={
|
||||
'code': fields.KeywordField()
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
'id': fields.IntegerField(),
|
||||
'street_name_1': fields.TextField(
|
||||
fields={'raw': fields.KeywordField()}
|
||||
),
|
||||
'postal_code': fields.KeywordField(),
|
||||
'coordinates': fields.GeoPointField(attr='location_field_indexing'),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class TagDocumentSerializer(serializers.Serializer):
|
|||
return get_translated_value(obj.label)
|
||||
|
||||
|
||||
class ProductTypeDocumentSerializer(serializers.Serializer):
|
||||
class ProductTypeSerializer(serializers.Serializer):
|
||||
"""Product type ES document serializer."""
|
||||
|
||||
id = serializers.IntegerField()
|
||||
|
|
@ -140,19 +140,6 @@ class AnotherCityDocumentShortSerializer(CityDocumentShortSerializer):
|
|||
return None
|
||||
|
||||
|
||||
class ProductEstablishmentDocumentSerializer(serializers.Serializer):
|
||||
"""Related to Product Establishment ES document serializer."""
|
||||
|
||||
id = serializers.IntegerField()
|
||||
name = serializers.CharField()
|
||||
slug = serializers.CharField()
|
||||
index_name = serializers.CharField()
|
||||
city = AnotherCityDocumentShortSerializer()
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance.establishment if instance and instance.establishment else None
|
||||
|
||||
|
||||
class AddressDocumentSerializer(serializers.Serializer):
|
||||
"""Address serializer for ES Document."""
|
||||
|
||||
|
|
@ -175,6 +162,34 @@ class AddressDocumentSerializer(serializers.Serializer):
|
|||
return None
|
||||
|
||||
|
||||
class PSAddressDocumentSerializer(serializers.Serializer):
|
||||
"""Address serializer for ES Document."""
|
||||
|
||||
id = serializers.IntegerField()
|
||||
street_name_1 = serializers.CharField()
|
||||
postal_code = serializers.CharField()
|
||||
|
||||
def to_representation(self, instance):
|
||||
if instance != AttrDict(d={}) or \
|
||||
(isinstance(instance, dict) and len(instance) != 0):
|
||||
return super().to_representation(instance)
|
||||
return None
|
||||
|
||||
|
||||
class ProductEstablishmentSerializer(serializers.Serializer):
|
||||
"""Related to Product Establishment ES document serializer."""
|
||||
|
||||
id = serializers.IntegerField()
|
||||
name = serializers.CharField()
|
||||
slug = serializers.CharField()
|
||||
index_name = serializers.CharField()
|
||||
city = AnotherCityDocumentShortSerializer()
|
||||
address = PSAddressDocumentSerializer(allow_null=True)
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance.establishment if instance and instance.establishment else None
|
||||
|
||||
|
||||
class ScheduleDocumentSerializer(serializers.Serializer):
|
||||
"""Schedule serializer for ES Document"""
|
||||
|
||||
|
|
@ -289,15 +304,15 @@ class EstablishmentDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
)
|
||||
|
||||
|
||||
class ProductDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
||||
class ProductDocumentSerializer(InFavoritesMixin):
|
||||
"""Product document serializer"""
|
||||
|
||||
tags = TagsDocumentSerializer(many=True, source='related_tags')
|
||||
subtypes = ProductSubtypeDocumentSerializer(many=True, allow_null=True)
|
||||
wine_colors = TagDocumentSerializer(many=True)
|
||||
grape_variety = TagDocumentSerializer(many=True)
|
||||
product_type = ProductTypeDocumentSerializer(allow_null=True)
|
||||
establishment_detail = ProductEstablishmentDocumentSerializer(source='establishment', allow_null=True)
|
||||
# product_type = ProductTypeSerializer(allow_null=True)
|
||||
establishment_detail = ProductEstablishmentSerializer(source='establishment', allow_null=True)
|
||||
wine_origins = WineOriginSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
|
|
@ -321,7 +336,6 @@ class ProductDocumentSerializer(InFavoritesMixin, DocumentSerializer):
|
|||
'subtypes',
|
||||
'wine_colors',
|
||||
'grape_variety',
|
||||
'establishment_detail',
|
||||
'average_price',
|
||||
'created',
|
||||
'wine_origins',
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ def update_document(sender, **kwargs):
|
|||
instance = kwargs['instance']
|
||||
|
||||
app_label_model_name_to_filter = {
|
||||
('location','country'): 'address__city__country',
|
||||
('location','city'): 'address__city',
|
||||
('location', 'country'): 'address__city__country',
|
||||
('location', 'city'): 'address__city',
|
||||
('location', 'address'): 'address',
|
||||
# todo: remove after migration
|
||||
('establishment', 'establishmenttype'): 'establishment_type',
|
||||
|
|
@ -34,8 +34,8 @@ def update_news(sender, **kwargs):
|
|||
model_name = sender._meta.model_name
|
||||
instance = kwargs['instance']
|
||||
app_label_model_name_to_filter = {
|
||||
('location','country'): 'country',
|
||||
('news','newstype'): 'news_type',
|
||||
('location', 'country'): 'country',
|
||||
('news', 'newstype'): 'news_type',
|
||||
('tag', 'tag'): 'tags',
|
||||
}
|
||||
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||
|
|
@ -52,9 +52,9 @@ def update_product(sender, **kwargs):
|
|||
model_name = sender._meta.model_name
|
||||
instance = kwargs['instance']
|
||||
app_label_model_name_to_filter = {
|
||||
('product','productstandard'): 'standards',
|
||||
('product', 'productstandard'): 'standards',
|
||||
('product', 'producttype'): 'product_type',
|
||||
('tag','tag'): 'tags',
|
||||
('tag', 'tag'): 'tags',
|
||||
('location', 'wineregion'): 'wine_region',
|
||||
('location', 'winesubregion'): 'wine_sub_region',
|
||||
('location', 'winevillage'): 'wine_village',
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user