Skip to content

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

Models adapted to Python3

Artur Smęt7cb82a9f2fe3
diff --git a/saleor/product/models/base_products.py b/saleor/product/models/base_products.py
index 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_literals
import re
from django.core.urlresolvers import reverse
+from django.utils.encoding import python_2_unicode_compatible
from django.db import models
from django.utils.safestring import mark_safe
from django.utils.translation import pgettext_lazy
@@ -12,6 +13,7 @@ from unidecode import unidecode
from ...core.utils.models import Subtyped
+@python_2_unicode_compatible
class 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.name
def get_absolute_url(self):
@@ -34,6 +36,7 @@ class Category(MPTTModel):
app_label = 'product'
+@python_2_unicode_compatible
class 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_compatible
class 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.name
def get_absolute_url(self):
diff --git a/saleor/product/models/discounts.py b/saleor/product/models/discounts.py
index 3a94b3cb03..c61cd2e9ab 100644
--- a/saleor/product/models/discounts.py
+++ b/saleor/product/models/discounts.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.conf import settings
from django.db import models
from django.utils.translation import pgettext_lazy
+from django.utils.encoding import python_2_unicode_compatible
from django_prices.models import PriceField
from prices import FixedDiscount
@@ -19,6 +20,7 @@ class ProductDiscountManager(models.Manager):
return self.get_query_set().filter(products=variant.product)
+@python_2_unicode_compatible
class 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.name
def __repr__(self):
diff --git a/saleor/product/models/images.py b/saleor/product/models/images.py
index a5539dbfb0..d4af7291c3 100644
--- a/saleor/product/models/images.py
+++ b/saleor/product/models/images.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django_images.models import Image
from django.utils.safestring import mark_safe
-
+from django.utils.encoding import python_2_unicode_compatible
from .base_products import Product
@@ -12,6 +12,7 @@ class ImageManager(models.Manager):
return self.get_query_set()[0]
+@python_2_unicode_compatible
class 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.py
index 8e488c7e4c..d8dfe02443 100644
--- a/saleor/product/models/variants.py
+++ b/saleor/product/models/variants.py
@@ -7,10 +7,12 @@ from satchless.item import Item, StockedItem
from django_prices.models import PriceField
from django.conf import settings
from django.core.urlresolvers import reverse
+from django.utils.encoding import python_2_unicode_compatible
from .discounts import get_product_discounts
+@python_2_unicode_compatible
class 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_compatible
class 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 = True
app_label = 'product'
- def __unicode__(self):
+ def __str__(self):
return self.name or self.product.name
def get_price_per_item(self, discounted=True, **kwargs):