Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Models adapted to Python3
Artur Smęt7cb82a9f2fe3
diff --git a/saleor/product/models/base_products.py b/saleor/product/models/base_products.pyindex b4b94c91a0..ef0e0a29cf 100644--- a/saleor/product/models/base_products.py+++ b/saleor/product/models/base_products.py@@ -2,6 +2,7 @@ from __future__ import unicode_literalsimport refrom django.core.urlresolvers import reverse+from django.utils.encoding import python_2_unicode_compatiblefrom django.db import modelsfrom django.utils.safestring import mark_safefrom django.utils.translation import pgettext_lazy@@ -12,6 +13,7 @@ from unidecode import unidecodefrom ...core.utils.models import Subtyped+@python_2_unicode_compatibleclass Category(MPTTModel):name = models.CharField(pgettext_lazy('Category field', 'name'), max_length=128)@@ -23,7 +25,7 @@ class Category(MPTTModel):'self', null=True, blank=True, related_name='children',verbose_name=pgettext_lazy('Category field', 'parent'))- def __unicode__(self):+ def __str__(self):return self.namedef get_absolute_url(self):@@ -34,6 +36,7 @@ class Category(MPTTModel):app_label = 'product'+@python_2_unicode_compatibleclass ProductCollection(models.Model):name = models.CharField(pgettext_lazy('Product Collection name', 'name'),max_length=100, db_index=True, unique=True)@@ -41,10 +44,11 @@ class ProductCollection(models.Model):class Meta:app_label = 'product'- def __unicode__(self):+ def __str__(self):return self.name+@python_2_unicode_compatibleclass Product(Subtyped, ItemRange):name = models.CharField(pgettext_lazy('Product field', 'name'), max_length=128)@@ -57,7 +61,7 @@ class Product(Subtyped, ItemRange):class Meta:app_label = 'product'- def __unicode__(self):+ def __str__(self):return self.namedef get_absolute_url(self):diff --git a/saleor/product/models/discounts.py b/saleor/product/models/discounts.pyindex 3a94b3cb03..c61cd2e9ab 100644--- a/saleor/product/models/discounts.py+++ b/saleor/product/models/discounts.py@@ -3,6 +3,7 @@ from __future__ import unicode_literalsfrom django.conf import settingsfrom django.db import modelsfrom django.utils.translation import pgettext_lazy+from django.utils.encoding import python_2_unicode_compatiblefrom django_prices.models import PriceFieldfrom prices import FixedDiscount@@ -19,6 +20,7 @@ class ProductDiscountManager(models.Manager):return self.get_query_set().filter(products=variant.product)+@python_2_unicode_compatibleclass FixedProductDiscount(models.Model):name = models.CharField(max_length=255)products = models.ManyToManyField(Product, blank=True)@@ -38,7 +40,7 @@ class FixedProductDiscount(models.Model):raise NotApplicable('Discount too high for this product')return FixedDiscount(self.discount, name=self.name)- def __unicode__(self):+ def __str__(self):return self.namedef __repr__(self):diff --git a/saleor/product/models/images.py b/saleor/product/models/images.pyindex a5539dbfb0..d4af7291c3 100644--- a/saleor/product/models/images.py+++ b/saleor/product/models/images.py@@ -3,7 +3,7 @@ from __future__ import unicode_literalsfrom django.db import modelsfrom django_images.models import Imagefrom django.utils.safestring import mark_safe-+from django.utils.encoding import python_2_unicode_compatiblefrom .base_products import Product@@ -12,6 +12,7 @@ class ImageManager(models.Manager):return self.get_query_set()[0]+@python_2_unicode_compatibleclass ProductImage(Image):product = models.ForeignKey(Product, related_name='images')@@ -21,7 +22,7 @@ class ProductImage(Image):ordering = ['id']app_label = 'product'- def __unicode__(self):+ def __str__(self):html = '<img src="%s" alt="">' % (self.get_absolute_url('admin'),)return mark_safe(html)diff --git a/saleor/product/models/variants.py b/saleor/product/models/variants.pyindex 8e488c7e4c..d8dfe02443 100644--- a/saleor/product/models/variants.py+++ b/saleor/product/models/variants.py@@ -7,10 +7,12 @@ from satchless.item import Item, StockedItemfrom django_prices.models import PriceFieldfrom django.conf import settingsfrom django.core.urlresolvers import reverse+from django.utils.encoding import python_2_unicode_compatiblefrom .discounts import get_product_discounts+@python_2_unicode_compatibleclass Color(models.Model):name = models.CharField(pgettext_lazy('Color name field', 'name'),max_length=100)@@ -20,7 +22,7 @@ class Color(models.Model):class Meta:app_label = 'product'- def __unicode__(self):+ def __str__(self):return self.name@@ -59,6 +61,7 @@ class ColoredVariants(models.Model):app_label = 'product'+@python_2_unicode_compatibleclass ProductVariant(models.Model, Item):name = models.CharField(pgettext_lazy('Product field', 'name'),max_length=128, blank=True, default='')@@ -72,7 +75,7 @@ class ProductVariant(models.Model, Item):abstract = Trueapp_label = 'product'- def __unicode__(self):+ def __str__(self):return self.name or self.product.namedef get_price_per_item(self, discounted=True, **kwargs):