product establishment_detail address

This commit is contained in:
alex 2019-12-11 09:10:49 +03:00
parent b5e1344b38
commit 41659958f7
4 changed files with 52 additions and 40 deletions

View File

@ -171,7 +171,7 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes,
default=None, help_text='{"en-GB":"some text"}') default=None, help_text='{"en-GB":"some text"}')
available = models.BooleanField(_('available'), default=True) available = models.BooleanField(_('available'), default=True)
product_type = models.ForeignKey(ProductType, on_delete=models.PROTECT, product_type = models.ForeignKey(ProductType, on_delete=models.PROTECT,
null=True, null=True, blank=True, default=None,
related_name='products', verbose_name=_('Type')) related_name='products', verbose_name=_('Type'))
subtypes = models.ManyToManyField(ProductSubType, blank=True, subtypes = models.ManyToManyField(ProductSubType, blank=True,
related_name='products', related_name='products',

View File

@ -14,12 +14,13 @@ class ProductDocument(Document):
description = fields.ObjectField(attr='description_indexing', description = fields.ObjectField(attr='description_indexing',
properties=OBJECT_FIELD_PROPERTIES) properties=OBJECT_FIELD_PROPERTIES)
product_type = fields.ObjectField(properties={ product_type = fields.ObjectField(
properties={
'id': fields.IntegerField(), 'id': fields.IntegerField(),
'name': fields.ObjectField(attr='name_indexing', properties=OBJECT_FIELD_PROPERTIES), 'name': fields.ObjectField(attr='name_indexing', properties=OBJECT_FIELD_PROPERTIES),
'index_name': fields.KeywordField(), 'index_name': fields.KeywordField(),
'use_subtypes': fields.BooleanField(), }
}) )
subtypes = fields.ObjectField( subtypes = fields.ObjectField(
properties={ properties={
'id': fields.IntegerField(), 'id': fields.IntegerField(),
@ -54,15 +55,12 @@ class ProductDocument(Document):
), ),
'address': fields.ObjectField( 'address': fields.ObjectField(
properties={ properties={
'city': fields.ObjectField( 'id': fields.IntegerField(),
properties={ 'street_name_1': fields.TextField(
'country': fields.ObjectField( fields={'raw': fields.KeywordField()}
properties={ ),
'code': fields.KeywordField() 'postal_code': fields.KeywordField(),
} 'coordinates': fields.GeoPointField(attr='location_field_indexing'),
)
}
)
} }
) )
} }

View File

@ -95,7 +95,7 @@ class TagDocumentSerializer(serializers.Serializer):
return get_translated_value(obj.label) return get_translated_value(obj.label)
class ProductTypeDocumentSerializer(serializers.Serializer): class ProductTypeSerializer(serializers.Serializer):
"""Product type ES document serializer.""" """Product type ES document serializer."""
id = serializers.IntegerField() id = serializers.IntegerField()
@ -140,19 +140,6 @@ class AnotherCityDocumentShortSerializer(CityDocumentShortSerializer):
return None 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): class AddressDocumentSerializer(serializers.Serializer):
"""Address serializer for ES Document.""" """Address serializer for ES Document."""
@ -175,6 +162,34 @@ class AddressDocumentSerializer(serializers.Serializer):
return None 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): class ScheduleDocumentSerializer(serializers.Serializer):
"""Schedule serializer for ES Document""" """Schedule serializer for ES Document"""
@ -289,15 +304,15 @@ class EstablishmentDocumentSerializer(InFavoritesMixin, DocumentSerializer):
) )
class ProductDocumentSerializer(InFavoritesMixin, DocumentSerializer): class ProductDocumentSerializer(InFavoritesMixin):
"""Product document serializer""" """Product document serializer"""
tags = TagsDocumentSerializer(many=True, source='related_tags') tags = TagsDocumentSerializer(many=True, source='related_tags')
subtypes = ProductSubtypeDocumentSerializer(many=True, allow_null=True) subtypes = ProductSubtypeDocumentSerializer(many=True, allow_null=True)
wine_colors = TagDocumentSerializer(many=True) wine_colors = TagDocumentSerializer(many=True)
grape_variety = TagDocumentSerializer(many=True) grape_variety = TagDocumentSerializer(many=True)
product_type = ProductTypeDocumentSerializer(allow_null=True) # product_type = ProductTypeSerializer(allow_null=True)
establishment_detail = ProductEstablishmentDocumentSerializer(source='establishment', allow_null=True) establishment_detail = ProductEstablishmentSerializer(source='establishment', allow_null=True)
wine_origins = WineOriginSerializer(many=True) wine_origins = WineOriginSerializer(many=True)
class Meta: class Meta:
@ -321,7 +336,6 @@ class ProductDocumentSerializer(InFavoritesMixin, DocumentSerializer):
'subtypes', 'subtypes',
'wine_colors', 'wine_colors',
'grape_variety', 'grape_variety',
'establishment_detail',
'average_price', 'average_price',
'created', 'created',
'wine_origins', 'wine_origins',

View File

@ -12,8 +12,8 @@ def update_document(sender, **kwargs):
instance = kwargs['instance'] instance = kwargs['instance']
app_label_model_name_to_filter = { app_label_model_name_to_filter = {
('location','country'): 'address__city__country', ('location', 'country'): 'address__city__country',
('location','city'): 'address__city', ('location', 'city'): 'address__city',
('location', 'address'): 'address', ('location', 'address'): 'address',
# todo: remove after migration # todo: remove after migration
('establishment', 'establishmenttype'): 'establishment_type', ('establishment', 'establishmenttype'): 'establishment_type',
@ -34,8 +34,8 @@ def update_news(sender, **kwargs):
model_name = sender._meta.model_name model_name = sender._meta.model_name
instance = kwargs['instance'] instance = kwargs['instance']
app_label_model_name_to_filter = { app_label_model_name_to_filter = {
('location','country'): 'country', ('location', 'country'): 'country',
('news','newstype'): 'news_type', ('news', 'newstype'): 'news_type',
('tag', 'tag'): 'tags', ('tag', 'tag'): 'tags',
} }
filter_name = app_label_model_name_to_filter.get((app_label, model_name)) 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 model_name = sender._meta.model_name
instance = kwargs['instance'] instance = kwargs['instance']
app_label_model_name_to_filter = { app_label_model_name_to_filter = {
('product','productstandard'): 'standards', ('product', 'productstandard'): 'standards',
('product', 'producttype'): 'product_type', ('product', 'producttype'): 'product_type',
('tag','tag'): 'tags', ('tag', 'tag'): 'tags',
('location', 'wineregion'): 'wine_region', ('location', 'wineregion'): 'wine_region',
('location', 'winesubregion'): 'wine_sub_region', ('location', 'winesubregion'): 'wine_sub_region',
('location', 'winevillage'): 'wine_village', ('location', 'winevillage'): 'wine_village',