added tags, image urls to product serializers
This commit is contained in:
parent
46662398e4
commit
f4b411e73d
|
|
@ -75,8 +75,8 @@ class Collection(ProjectBaseMixin, CollectionDateMixin,
|
|||
default=None, help_text='{"en-GB":"some text"}')
|
||||
slug = models.SlugField(max_length=50, unique=True,
|
||||
verbose_name=_('Collection slug'), editable=True, null=True)
|
||||
old_id = models.IntegerField(null=True, blank=True)
|
||||
|
||||
old_id=models.IntegerField(null=True, blank=True)
|
||||
objects = CollectionQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -245,7 +245,20 @@ class Product(TranslatedFieldsMixin, BaseAttributes):
|
|||
def main_image(self):
|
||||
qs = ProductGallery.objects.filter(product=self, is_main=True)
|
||||
if qs.exists():
|
||||
return qs.first().image.image
|
||||
return qs.first().image
|
||||
|
||||
@property
|
||||
def main_image_url(self):
|
||||
return self.main_image.image if self.main_image else None
|
||||
|
||||
@property
|
||||
def preview_main_image_url(self):
|
||||
return self.main_image.get_image_url('product_preview') if self.main_image else None
|
||||
|
||||
@property
|
||||
def related_tags(self):
|
||||
return self.tags.exclude(
|
||||
category__index_name__in=['sugar-content', 'wine-color', 'bottles-produced'])
|
||||
|
||||
|
||||
class OnlineProductManager(ProductManager):
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ class ProductBaseSerializer(serializers.ModelSerializer):
|
|||
product_type = serializers.CharField(source='product_type_translated_name')
|
||||
subtypes = ProductSubTypeBaseSerializer(many=True)
|
||||
establishment = EstablishmentShortSerializer()
|
||||
tags = TagBaseSerializer(source='related_tags', many=True)
|
||||
preview_image_url = serializers.ImageField(source='preview_main_image_url', allow_null=True)
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
|
@ -88,6 +90,8 @@ class ProductBaseSerializer(serializers.ModelSerializer):
|
|||
'public_mark',
|
||||
'establishment',
|
||||
'vintage',
|
||||
'tags',
|
||||
'preview_image_url',
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -104,7 +108,7 @@ class ProductDetailSerializer(ProductBaseSerializer):
|
|||
wine_colors = TagBaseSerializer(many=True)
|
||||
bottles_produced = TagBaseSerializer(many=True)
|
||||
sugar_contents = TagBaseSerializer(many=True)
|
||||
main_image = serializers.ImageField(allow_null=True)
|
||||
image_url = serializers.ImageField(source='main_image_url', allow_null=True)
|
||||
|
||||
class Meta(ProductBaseSerializer.Meta):
|
||||
fields = ProductBaseSerializer.Meta.fields + [
|
||||
|
|
@ -118,7 +122,7 @@ class ProductDetailSerializer(ProductBaseSerializer):
|
|||
'wine_colors',
|
||||
'bottles_produced',
|
||||
'sugar_contents',
|
||||
'main_image',
|
||||
'image_url',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -357,6 +357,7 @@ THUMBNAIL_ALIASES = {
|
|||
'news_editor_web': {'size': (940, 430), }, # при загрузке через контент эдитор
|
||||
'news_editor_mobile': {'size': (343, 260), }, # через контент эдитор в мобильном браузерe
|
||||
'avatar_comments_web': {'size': (116, 116), },
|
||||
'product_preview': {'size': (300, 260), },
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user