changed representation of product name in ProductBaseSerializer

This commit is contained in:
Anatoly 2019-11-14 16:35:33 +03:00
parent e08bd8508a
commit a6d064daba
2 changed files with 10 additions and 1 deletions

View File

@ -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):

View File

@ -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)