Use the company thumbnail in the Company API

This commit is contained in:
Oliver Walters 2020-04-07 11:27:56 +10:00
parent e0655f61d8
commit ae9ef04013
2 changed files with 10 additions and 2 deletions

View File

@ -122,6 +122,14 @@ class Company(models.Model):
else: else:
return os.path.join(settings.STATIC_URL, 'img/blank_image.png') 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 @property
def part_count(self): def part_count(self):
""" The number of parts supplied by this company """ """ The number of parts supplied by this company """

View File

@ -32,7 +32,7 @@ class CompanySerializer(InvenTreeModelSerializer):
url = serializers.CharField(source='get_absolute_url', read_only=True) url = serializers.CharField(source='get_absolute_url', read_only=True)
part_count = serializers.CharField(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: class Meta:
model = Company model = Company
@ -64,7 +64,7 @@ class SupplierPartSerializer(InvenTreeModelSerializer):
part_detail = PartBriefSerializer(source='part', many=False, read_only=True) part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
supplier_name = serializers.CharField(source='supplier.name', 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) pricing = serializers.CharField(source='unit_pricing', read_only=True)