From a6d064dabab1f1f565c58d8ab5cd226bffd966c0 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 14 Nov 2019 16:35:33 +0300 Subject: [PATCH] changed representation of product name in ProductBaseSerializer --- apps/product/models.py | 10 +++++++++- apps/product/serializers/common.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/product/models.py b/apps/product/models.py index 6065871c..b6529c19 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -258,7 +258,15 @@ class Product(TranslatedFieldsMixin, BaseAttributes): def related_tags(self): return self.tags.exclude( category__index_name__in=['sugar-content', 'wine-color', 'bottles-produced', - 'serial-number']) + 'serial-number', 'grape-variety']) + + @property + def display_name(self): + name = f'{self.name} ' \ + f'({self.vintage if self.vintage else "BSA"})' + if self.establishment.name: + name = f'{self.establishment.name} - ' + name + return name class OnlineProductManager(ProductManager): diff --git a/apps/product/serializers/common.py b/apps/product/serializers/common.py index 364fd3c9..9145499d 100644 --- a/apps/product/serializers/common.py +++ b/apps/product/serializers/common.py @@ -85,6 +85,7 @@ class ProductStandardBaseSerializer(serializers.ModelSerializer): class ProductBaseSerializer(serializers.ModelSerializer): """Product base serializer.""" + name = serializers.CharField(source='display_name', read_only=True) product_type = serializers.CharField(source='product_type_translated_name', read_only=True) subtypes = ProductSubTypeBaseSerializer(many=True, read_only=True) establishment_detail = EstablishmentShortSerializer(source='establishment', read_only=True)