From e303e15f32313bc24c5d5fece870d389a7730c8f Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 21 Nov 2019 10:28:17 +0300 Subject: [PATCH] added two characteristics to wine detail serializer --- apps/product/models.py | 6 ++++++ apps/product/serializers/common.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/apps/product/models.py b/apps/product/models.py index e562e4a3..f499afee 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -267,6 +267,12 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes, HasTagsM def bottle_sizes(self): return self.tags.filter(category__index_name='bottle_size') + @property + def alcohol_percentage(self): + qs = self.tags.filter(category__index_name='alcohol_percentage') + if qs.exists(): + return qs.first() + @property def related_tags(self): return super().visible_tags.exclude(category__index_name__in=[ diff --git a/apps/product/serializers/common.py b/apps/product/serializers/common.py index a0a56337..14eff642 100644 --- a/apps/product/serializers/common.py +++ b/apps/product/serializers/common.py @@ -128,6 +128,8 @@ class ProductDetailSerializer(ProductBaseSerializer): bottles_produced = TagBaseSerializer(many=True, read_only=True) sugar_contents = TagBaseSerializer(many=True, read_only=True) grape_variety = TagBaseSerializer(many=True, read_only=True) + bottle_sizes = TagBaseSerializer(many=True, read_only=True) + alcohol_percentage = TagBaseSerializer(read_only=True) image_url = serializers.URLField(allow_null=True, read_only=True) new_image = ImageBaseSerializer(source='crop_main_image', allow_null=True, read_only=True) @@ -146,6 +148,8 @@ class ProductDetailSerializer(ProductBaseSerializer): 'new_image', 'grape_variety', 'average_price', + 'bottle_sizes', + 'alcohol_percentage', ]