From ae9ef040130dc5aa7ba62cf9b8584e0e2c28f840 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 7 Apr 2020 11:27:56 +1000 Subject: [PATCH] Use the company thumbnail in the Company API --- InvenTree/company/models.py | 8 ++++++++ InvenTree/company/serializers.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 59a6a2b37a..69c98a008a 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -122,6 +122,14 @@ class Company(models.Model): else: return os.path.join(settings.STATIC_URL, 'img/blank_image.png') + def get_thumbnail_url(self): + """ Return the URL for the thumbnail image for this Company """ + + if self.image: + return os.path.join(settings.MEDIA_URL, str(self.image.thumbnail.url)) + else: + return os.path.join(settings.STATIC_URL, 'img/blank_image.thumbnail.png') + @property def part_count(self): """ The number of parts supplied by this company """ diff --git a/InvenTree/company/serializers.py b/InvenTree/company/serializers.py index 161edd286e..935712a180 100644 --- a/InvenTree/company/serializers.py +++ b/InvenTree/company/serializers.py @@ -32,7 +32,7 @@ class CompanySerializer(InvenTreeModelSerializer): url = serializers.CharField(source='get_absolute_url', read_only=True) part_count = serializers.CharField(read_only=True) - image = serializers.CharField(source='get_image_url', read_only=True) + image = serializers.CharField(source='get_thumbnail_url', read_only=True) class Meta: model = Company @@ -64,7 +64,7 @@ class SupplierPartSerializer(InvenTreeModelSerializer): part_detail = PartBriefSerializer(source='part', many=False, read_only=True) supplier_name = serializers.CharField(source='supplier.name', read_only=True) - supplier_logo = serializers.CharField(source='supplier.get_image_url', read_only=True) + supplier_logo = serializers.CharField(source='supplier.get_thumbnail_url', read_only=True) pricing = serializers.CharField(source='unit_pricing', read_only=True)