Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Move get_first_image implementation to Product model

Artur Smętd58220f049d1
diff --git a/saleor/product/models/base.py b/saleor/product/models/base.py
index 14278da979..39805dd23a 100644
--- a/saleor/product/models/base.py
+++ b/saleor/product/models/base.py
@@ -127,6 +127,13 @@ class Product(models.Model, ItemRange):
return category
return None
+ def get_first_image(self):
+ first_image = self.images.first()
+
+ if first_image:
+ return first_image.image
+ return None
+
@python_2_unicode_compatible
class ProductVariant(models.Model, Item):
@@ -214,11 +221,7 @@ class ProductVariant(models.Model, Item):
self.display_variant(attributes=attributes))
def get_first_image(self):
- first_image = self.product.images.first()
-
- if first_image:
- return first_image.image
- return None
+ return self.product.get_first_image()
def select_stockrecord(self, quantity=1):
# By default selects stock with lowest cost price