Skip to content

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

Add availability API and switch to versatileimagefield

Patryk Zawadzkiad88e936941e
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.py
index 97d0bbb2f4..63d4b463f3 100755
--- a/saleor/cart/__init__.py
+++ b/saleor/cart/__init__.py
@@ -6,7 +6,6 @@ from django.utils.encoding import python_2_unicode_compatible, smart_text
from prices import Price
from satchless import cart
from satchless.item import ItemList, partition
-from saleor.product.models import Product
CART_SESSION_KEY = 'cart'
@@ -52,6 +51,8 @@ class Cart(cart.Cart):
@classmethod
def for_session_cart(cls, session_cart, discounts=None):
+ from saleor.product.models import Product
+
cart = Cart(session_cart, discounts=discounts)
product_ids = [item.data['product_id'] for item in session_cart]
products = Product.objects.filter(id__in=product_ids)
diff --git a/saleor/dashboard/templates/dashboard/base.html b/saleor/dashboard/templates/dashboard/base.html
index 7299cdc89d..7ececa701a 100644
--- a/saleor/dashboard/templates/dashboard/base.html
+++ b/saleor/dashboard/templates/dashboard/base.html
@@ -9,15 +9,13 @@
<title>{% block title %}{% trans "Dashboard - Saleor" %}{% endblock %}</title>
- <!-- Page-Level Plugin CSS - Blank -->
-
- <!-- SB Admin CSS - Include with every page -->
- {% if debug %}
+ {% if debug %}
<link rel="stylesheet/less" type="text/css" href="{% static "less/dashboard.less" %}">
<script type="text/javascript" src="{% static "dist/js/less.min.js" %}"></script>
{% else %}
<link rel="stylesheet" type="text/css" href="{% static "css/dashboard.css" %}">
{% endif %}
+ <link rel="stylesheet" type="text/css" href="{% static "versatileimagefield/css/versatileimagefield.css" %}">
{% block custom_css %}
{% endblock %}
</head>
@@ -62,6 +60,7 @@
<!-- Core Scripts - Include with every page -->
<script src="{% static "dist/js/jquery.min.js" %}"></script>
<script src="{% static "dist/js/bootstrap.min.js" %}"></script>
+<script src="{% static "versatileimagefield/js/versatileimagefield.js" %}"></script>
{% block custom_js %}{% endblock %}
</body>
diff --git a/saleor/dashboard/templates/dashboard/includes/_formset_table.html b/saleor/dashboard/templates/dashboard/includes/_formset_table.html
deleted file mode 100644
index 457351b56d..0000000000
--- a/saleor/dashboard/templates/dashboard/includes/_formset_table.html
+++ /dev/null
@@ -1,49 +0,0 @@
-<table class="table">
- <thead>
- <tr>
- {% for field in formset.0.visible_fields %}
- <th>{{ field.label }}</th>
- {% endfor %}
- </tr>
- </thead>
- <tbody>
- {% for form in formset.initial_forms %}
- {% for field in form.hidden_fields %}
- {{ field }}
- {% endfor %}
- <tr>
- {% for field in form.visible_fields %}
- <td>
- <div class="{% if field.errors %} has-error{% endif %}{% if field.required %} required{% endif %}">
- {{ field }}
- {% if field.errors %}
- {% for error in field.errors %}
- <span class="label label-danger">{{ error }}</span>
- {% endfor %}
- {% endif %}
- </div>
- </td>
- {% endfor %}
- </tr>
- {% endfor %}
- {% for form in formset.extra_forms %}
- {% for field in form.hidden_fields %}
- {{ field }}
- {% endfor %}
- <tr>
- {% for field in form.visible_fields %}
- <td>
- <div class="{% if field.errors %} has-error{% endif %}{% if field.required %} required{% endif %}">
- {{ field }}
- {% if field.errors %}
- {% for error in field.errors %}
- <span class="label label-danger">{{ error }}</span>
- {% endfor %}
- {% endif %}
- </div>
- </td>
- {% endfor %}
- </tr>
- {% endfor %}
- </tbody>
-</table>
\ No newline at end of file
diff --git a/saleor/dashboard/templates/dashboard/product/list.html b/saleor/dashboard/templates/dashboard/product/list.html
index 63c66e9291..f6987d6477 100644
--- a/saleor/dashboard/templates/dashboard/product/list.html
+++ b/saleor/dashboard/templates/dashboard/product/list.html
@@ -1,7 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load prices_i18n %}
-{% load images %}
{% load bootstrap %}
{% block title %}{% trans "Products" %} - {{ block.super }}{% endblock %}
@@ -28,25 +27,24 @@
<table class="table">
<thead>
<tr>
- <th>{% trans "Image" %}</th>
- <th>{% trans "Name" %}</th>
- <th>{% trans "Collection" %}</th>
- <th>{% trans "Price" %}</th>
+ <th colspan="2" class="col-sm-6">{% trans "Name" %}</th>
+ <th class="col-sm-4">{% trans "Collection" %}</th>
+ <th class="col-sm-2 text-right">{% trans "Price" %}</th>
</tr>
</thead>
<tbody>
{% for product in products %}
<tr>
- <td>
+ <td class="col-sm-1">
{% if product.images.exists %}
- <img class="img-responsive" src="{{ product.images.first|at_size:"admin" }}" alt="">
+ <img class="img-responsive" src="{{ product.images.first.image.crop.50x50 }}" alt="">
{% else %}
<img class="img-responsive" src="http://placehold.it/50x50/&text=Product Image" alt="">
{% endif %}
</td>
- <td><a href="{% url 'dashboard:product-update' pk=product.pk %}">{{ product.name }}</a></td>
+ <td class="col-sm-5"><a href="{% url 'dashboard:product-update' pk=product.pk %}">{{ product.name }}</a></td>
<td>{{ product.collection }}</td>
- <td>{% gross product.price %}</td>
+ <td class="text-right">{% gross product.price %}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/saleor/dashboard/templates/dashboard/product/product_form.html b/saleor/dashboard/templates/dashboard/product/product_form.html
index 968a0f26e4..39b66ba1dc 100644
--- a/saleor/dashboard/templates/dashboard/product/product_form.html
+++ b/saleor/dashboard/templates/dashboard/product/product_form.html
@@ -2,7 +2,6 @@
{% load prices_i18n %}
{% load i18n %}
{% load bootstrap %}
-{% load images %}
{% load static %}
{% block title %}{{ title }} - {% trans "Products" %} - {{ block.super }}{% endblock %}
@@ -38,9 +37,73 @@
<div class="panel-heading">
<span class="panel-title">{% trans "Variants" %}</span>
</div>
- <div class="panel-body">
- {% include "dashboard/includes/_formset_table.html" with formset=variant_formset %}
- </div>
+ <table class="table">
+ <thead>
+ <tr>
+ <th>{% trans "SKU" %}</th>
+ {% for field in variant_formset.0.visible_fields %}
+ {% if field.name != 'sku' and field.name != 'DELETE' %}
+ <th>{{ field.label }}</th>
+ {% endif %}
+ {% endfor %}
+ <th class="text-right"><i class="glyphicon glyphicon-trash"></i></th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for form in variant_formset.initial_forms %}
+ <tr>
+ <td>
+ {% for field in form.hidden_fields %}
+ {{ field }}
+ {% endfor %}
+ {{ form.sku|as_vertical_form:False }}
+ </td>
+ {% for field in form.visible_fields %}
+ {% if field.name != 'sku' and field.name != 'DELETE' %}
+ <td>
+ <div class="{% if field.errors %} has-error{% endif %}{% if field.required %} required{% endif %}">
+ {{ field|as_vertical_form:False }}
+ {% if field.errors %}
+ {% for error in field.errors %}
+ <span class="label label-danger">{{ error }}</span>
+ {% endfor %}
+ {% endif %}
+ </div>
+ </td>
+ {% endif %}
+ {% endfor %}
+ <td class="text-right">
+ {{ form.DELETE }}
+ </td>
+ </tr>
+ {% endfor %}
+ {% for form in variant_formset.extra_forms %}
+ <tr>
+ <td>
+ {% for field in form.hidden_fields %}
+ {{ field }}
+ {% endfor %}
+ {{ form.sku|as_vertical_form:False }}
+ </td>
+ {% for field in form.visible_fields %}
+ {% if field.name != 'sku' and field.name != 'DELETE' %}
+ <td>
+ <div class="{% if field.errors %} has-error{% endif %}{% if field.required %} required{% endif %}">
+ {{ field|as_vertical_form:False }}
+ {% if field.errors %}
+ {% for error in field.errors %}
+ <span class="label label-danger">{{ error }}</span>
+ {% endfor %}
+ {% endif %}
+ </div>
+ </td>
+ {% endif %}
+ {% endfor %}
+ <td></td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
</div>
{{ image_formset.management_form }}
@@ -48,9 +111,35 @@
<div class="panel-heading">
<span class="panel-title">{% trans "Images" %}</span>
</div>
- <div class="panel-body">
- {% include "dashboard/includes/_formset_table.html" with formset=image_formset %}
- </div>
+ <table class="table">
+ <thead>
+ <tr>
+ <th colspan="1" class="col-sm-11">{% trans "Image" %}</th>
+ <th class="text-right"><i class="glyphicon glyphicon-trash"></i></th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for form in image_formset.initial_forms %}
+ <tr>
+ <td>
+ {{ form.image }}
+ </td>
+ <td class="text-right">
+ {{ form.DELETE }}
+ </td>
+ </tr>
+ {% endfor %}
+ {% for form in image_formset.extra_forms %}
+ <tr>
+ <td>
+ {{ form.image }}
+ </td>
+ <td></td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+
</div>
</div>
@@ -61,7 +150,7 @@
</div>
<div class="panel-body">
{% if product.images.exists %}
- <img class="img-responsive" src="{{ product.images.first|at_size:"small" }}" alt="">
+ <img class="img-responsive" src="{{ product.images.first.image.thumbnail.300x300 }}" alt="">
{% else %}
<img class="img-responsive" src="http://placehold.it/300x300/&text=Product Image" alt="">
{% endif %}
diff --git a/saleor/product/forms.py b/saleor/product/forms.py
index 47ad449d66..91793f4c9f 100644
--- a/saleor/product/forms.py
+++ b/saleor/product/forms.py
@@ -21,8 +21,7 @@ class ShirtForm(AddToCartForm):
def __init__(self, *args, **kwargs):
super(ShirtForm, self).__init__(*args, **kwargs)
available_sizes = [
- (p.size, p.get_size_display()) for p in self.product.variants.all()
- ]
+ (p.size, p.get_size_display()) for p in self.product.variants.all()]
self.fields['size'].choices = available_sizes
def get_variant(self, clean_data):
@@ -36,8 +35,7 @@ class ShirtAdminForm(forms.ModelForm):
model = Shirt
exclude = []
widgets = {
- 'collection': AutoCompleteWidget(CollectionLookup)
- }
+ 'collection': AutoCompleteWidget(CollectionLookup)}
class ProductVariantInline(forms.models.BaseInlineFormSet):
diff --git a/saleor/product/models/base.py b/saleor/product/models/base.py
index baf97783ee..61a970b24a 100644
--- a/saleor/product/models/base.py
+++ b/saleor/product/models/base.py
@@ -84,3 +84,6 @@ class Product(models.Model, ItemRange):
return self.get_formatted_price(price)
admin_get_price_max.short_description = pgettext_lazy(
'Product admin page', 'Maximum price')
+
+ def is_available(self):
+ return False
diff --git a/saleor/product/models/images.py b/saleor/product/models/images.py
index 7506cf8db7..cd3cf9a2ea 100644
--- a/saleor/product/models/images.py
+++ b/saleor/product/models/images.py
@@ -1,9 +1,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 versatileimagefield.fields import VersatileImageField, PPOIField
from .base import Product
@@ -13,17 +11,14 @@ class ImageManager(models.Manager):
return self.get_queryset()[0]
-@python_2_unicode_compatible
-class ProductImage(Image):
+class ProductImage(models.Model):
product = models.ForeignKey(Product, related_name='images')
+ image = VersatileImageField(
+ upload_to='products', ppoi_field='ppoi', blank=False)
+ ppoi = PPOIField()
objects = ImageManager()
class Meta:
ordering = ['id']
app_label = 'product'
-
- def __str__(self):
- html = '<img src="%s" alt="">' % (
- self.get_absolute_url('admin'),)
- return mark_safe(html)
diff --git a/saleor/product/models/products.py b/saleor/product/models/products.py
index 71dce8e431..eb5b4a6763 100644
--- a/saleor/product/models/products.py
+++ b/saleor/product/models/products.py
@@ -1,20 +1,21 @@
from __future__ import unicode_literals
-from django.utils.translation import pgettext_lazy
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+from django.utils.translation import pgettext_lazy
from .base import Product
from .variants import (ProductVariant, PhysicalProduct, ColoredVariant,
StockedProduct)
-class Bag(Product, PhysicalProduct, ColoredVariant):
+class Bag(PhysicalProduct, Product, ColoredVariant):
class Meta:
app_label = 'product'
-class Shirt(Product, PhysicalProduct, ColoredVariant):
+class Shirt(PhysicalProduct, Product, ColoredVariant):
class Meta:
app_label = 'product'
@@ -28,8 +29,9 @@ class BagVariant(ProductVariant, StockedProduct):
app_label = 'product'
+@python_2_unicode_compatible
class ShirtVariant(ProductVariant, StockedProduct):
-
+
SIZE_CHOICES = (
('xs', pgettext_lazy('Variant size', 'XS')),
('s', pgettext_lazy('Variant size', 'S')),
@@ -39,7 +41,12 @@ class ShirtVariant(ProductVariant, StockedProduct):
('xxl', pgettext_lazy('Variant size', 'XXL')))
product = models.ForeignKey(Shirt, related_name='variants')
- size = models.CharField(choices=SIZE_CHOICES, max_length=3)
+ size = models.CharField(
+ pgettext_lazy('Variant field', 'size'), choices=SIZE_CHOICES,
+ max_length=3)
class Meta:
- app_label = 'product'
\ No newline at end of file
+ app_label = 'product'
+
+ def __str__(self):
+ return '%s (%s)' % (self.product.name, self.size)
diff --git a/saleor/product/models/variants.py b/saleor/product/models/variants.py
index cc0c4313e2..7d635d9226 100644
--- a/saleor/product/models/variants.py
+++ b/saleor/product/models/variants.py
@@ -39,6 +39,9 @@ class StockedProduct(models.Model, StockedItem):
def get_stock(self):
return self.stock
+ def is_available(self):
+ return self.get_stock() > 0
+
class PhysicalProduct(models.Model):
weight = models.DecimalField(max_digits=6, decimal_places=2)
@@ -52,17 +55,21 @@ class PhysicalProduct(models.Model):
pgettext_lazy('Product field', 'price'),
currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=4)
+ class Meta:
+ abstract = True
+ app_label = 'product'
+
def get_weight(self):
try:
return self.weight
except AttributeError:
return self.product.weight
- class Meta:
- abstract = True
- app_label = 'product'
+ def is_available(self):
+ return any(variant.is_available() for variant in self)
+@python_2_unicode_compatible
class ColoredVariant(models.Model):
color = models.ForeignKey(Color)
@@ -70,13 +77,14 @@ class ColoredVariant(models.Model):
abstract = True
app_label = 'product'
+ def __str__(self):
+ return '%s (%s)' % (self.product.name, self.color)
+
@python_2_unicode_compatible
class ProductVariant(models.Model, Item):
- name = models.CharField(pgettext_lazy('Product field', 'name'),
- max_length=128, blank=True, default='')
sku = models.CharField(
- pgettext_lazy('Product field', 'sku'), max_length=32, unique=True)
+ pgettext_lazy('Product field', 'SKU'), max_length=32, unique=True)
# override the price attribute to implement per-variant pricing
price = None
@@ -85,7 +93,7 @@ class ProductVariant(models.Model, Item):
app_label = 'product'
def __str__(self):
- return self.name or self.product.name
+ return self.product.name
def get_price_per_item(self, discounts=None, **kwargs):
if self.price is not None:
@@ -116,8 +124,7 @@ class ProductVariant(models.Model, Item):
'product_name': str(self),
'product_id': self.product.pk,
'variant_id': self.pk,
- 'unit_price': str(self.get_price_per_item().gross)
- }
+ 'unit_price': str(self.get_price_per_item().gross)}
def is_shipping_required(self):
return True
diff --git a/saleor/product/templates/category/index.html b/saleor/product/templates/category/index.html
index 719dc91cc6..74e91bf8dc 100644
--- a/saleor/product/templates/category/index.html
+++ b/saleor/product/templates/category/index.html
@@ -1,12 +1,9 @@
{% extends "base.html" %}
{% load i18n %}
-{% load at_size from images %}
{% load slice from shop %}
{% load price_range from price_ranges %}
{% load discounted_price_range price_difference from discount %}
-
-
{% block title %}{{ category }} — {{ block.super }}{% endblock %}
{% block breadcrumb %}
@@ -20,23 +17,24 @@
<div class="row">
{% for product in row %}
<div class="col-sm-6">
- {% with price_range=product|discounted_price_range:request.discounts undiscounted=product.get_price_range %}
- {% with discount=undiscounted.min_price|price_difference:price_range.min_price %}
- <h3><a href="{{ product.get_absolute_url }}">{{ product }}</a>
- {% if undiscounted.min_price != price_range.min_price %}
- <span class="label label-success">{% trans "Discount!" %}</span>
- </h3>
- {% endif %}
- <h4>{% price_range price_range %}</h4>
- {% endwith %}
- {% endwith %}
-
-
{% if product.images.exists %}
<a href="{{ product.get_absolute_url }}">
- <img class="img-responsive" src="{{ product.images.first|at_size:"normal" }}" alt="">
+ <img class="img-responsive" src="{{ product.images.first.image.thumbnail.750x750 }}" alt="">
</a>
{% endif %}
+ <h3><a href="{{ product.get_absolute_url }}">{{ product }}</a></h3>
+ {% if product.is_available %}
+ {% with price_range=product|discounted_price_range:request.discounts undiscounted=product.get_price_range %}
+ {% with discount=undiscounted.min_price|price_difference:price_range.min_price %}
+ <h4>
+ {% price_range price_range %}
+ {% if undiscounted.min_price != price_range.min_price %}
+ <span class="label label-success">{% trans "Discount!" %}</span>
+ {% endif %}
+ </h4>
+ {% endwith %}
+ {% endwith %}
+ {% endif %}
</div>
{% endfor %}
</div>
diff --git a/saleor/product/templates/product/details.html b/saleor/product/templates/product/details.html
index 7e2e4f113b..18520f1368 100644
--- a/saleor/product/templates/product/details.html
+++ b/saleor/product/templates/product/details.html
@@ -3,7 +3,6 @@
{% load as_vertical_form from bootstrap %}
{% load discounted_price_range price_difference from discount %}
{% load i18n %}
-{% load at_size from images %}
{% load gross from prices_i18n %}
{% load markdown from markdown %}
{% load price_range from price_ranges %}
@@ -17,10 +16,6 @@
{% endblock breadcrumb %}
{% block outercontent %}
-
-{% with price_range=product|discounted_price_range:request.discounts undiscounted=product.get_price_range %}
-{% with discount=undiscounted.min_price|price_difference:price_range.min_price %}
-
<div itemscope itemtype="http://schema.org/Product">
<div class="row">
<div class="col-sm-6 col-sm-push-6">
@@ -28,57 +23,72 @@
{{ product }}
</h1>
- <p class="lead" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
- {% if undiscounted.min_price != price_range.min_price %}
- <span class="price undiscounted">{% price_range undiscounted %}</span>
- <br>
- <span class="price">{% price_range price_range %}</span>
- <br>
- <small class="label label-success">{% trans "You save" %} {% gross discount %}</small>
- {% else %}
- <span class="price">{% price_range price_range %}</span>
- {% endif %}
- </p>
+ {% if product.is_available %}
+ {% with price_range=product|discounted_price_range:request.discounts undiscounted=product.get_price_range %}
+ {% with discount=undiscounted.min_price|price_difference:price_range.min_price %}
+ <p class="lead" itemprop="offers" itemscope itemtype="http://schema.org/Offer"
+ {% if undiscounted.min_price != price_range.min_price %}
+ <span class="price undiscounted">{% price_range undiscounted %}</span>
+ <br>
+ <span class="price">{% price_range price_range %}</span>
+ <br>
+ <small class="label label-success">{% trans "You save" %} {% gross discount %}</small>
+ {% else %}
+ <span class="price">{% price_range price_range %}</span>
+ {% endif %}
+ </p>
+ {% endwith %}
+ {% endwith %}
+ {% endif %}
<hr>
<div class="visible-xs">
- <img class="img-responsive" src="{{ product.images.first|at_size:"normal" }}" alt="">
+ <img class="img-responsive" src="{{ product.images.first.image.thumbnail.750x750 }}" alt="">
<hr>
</div>
- {% if related_products %}
- <label>{% trans "This collection" %}</label>
+ {% if product.is_available %}
+ {% block orderform %}
+ <form role="form" class="product-form form-vertical" method="post" action=".">
+ {% csrf_token %}
+ {{ form|as_vertical_form }}
- <div class="row product-related">
- {% for related in related_products %}
- <a href="{{ related.get_absolute_url }}" class="col-xs-3">
- <img src="{{ related.images.first|at_size:"small" }}" alt=""
- class="thumbnail img-responsive{% if related.id == product.id %} active{% endif %}">
- </a>
- {% endfor %}
- </div>
+ <div class="form-group">
+ <button class="btn btn-lg btn-block btn-primary">
+ {% trans "Add to cart" %}
+ </button>
+ </div>
+ </form>
+ {% endblock %}
+ {% else %}
+ <p class="alert alert-warning">{% trans "This product is currently <strong>unavailable</strong>." %}</p>
{% endif %}
- {% block orderform %}
- <form role="form" class="product-form form-vertical" method="post" action=".">
- {% csrf_token %}
- {{ form|as_vertical_form }}
-
- <div class="form-group">
- <button class="btn btn-lg btn-block btn-primary">
- {% trans "Add to cart" %}
- </button>
- </div>
- </form>
- {% endblock %}
-
<hr>
<div itemprop="description">
{{ product.description|markdown }}
</div>
+
+ {% if related_products %}
+ <hr>
+
+ <h4>{% trans "Also in this collection" %}</h4>
+
+ <div class="row product-related">
+ {% for related in related_products %}
+ {% if related.id != product.id %}
+ <a href="{{ related.get_absolute_url }}" class="col-xs-3">
+ <img src="{{ related.images.first.image.crop.280x280 }}" alt=""
+ class="thumbnail img-responsive">
+ </a>
+ {% endif %}
+ {% endfor %}
+ </div>
+ {% endif %}
+
</div>
{% with images=product.images.all %}
@@ -95,7 +105,7 @@
{% for image in images %}
<div class="item{% if forloop.first %} active{% endif %}">
<a href="#" data-toggle="modal" data-target="#modal-{{ forloop.counter }}">
- <img class="img-responsive" src="{{ image|at_size:"normal" }}" alt="">
+ <img class="img-responsive" src="{{ image.image.thumbnail.750x750 }}" alt="">
</a>
</div>
{% endfor %}
@@ -130,7 +140,7 @@
<div class="product-gallery row">
{% for image in images %}
<a href="{{ image.image.url }}" target="_blank" class="product-gallery-item col-xs-6 col-md-3">
- <img class="thumbnail img-responsive" src="{{ image|at_size:"small" }}" alt="">
+ <img class="thumbnail img-responsive" src="{{ image.image.crop.280x280 }}" alt="">
</a>
{% endfor %}
</div>
@@ -138,8 +148,6 @@
{% endwith %}
</div>
</div>
-{% endwith %}
-{% endwith %}
{% endblock outercontent %}
{% block footer_scripts %}
diff --git a/saleor/product/templatetags/discount.py b/saleor/product/templatetags/discount.py
index 227d01a3b7..33359da591 100644
--- a/saleor/product/templatetags/discount.py
+++ b/saleor/product/templatetags/discount.py
@@ -7,10 +7,12 @@ register = template.Library()
def discounted_price(item, discounts):
return item.get_price(discounts=discounts)
+
@register.filter
def discounted_price_range(item, discounts):
return item.get_price_range(discounts=discounts)
+
@register.filter
def price_difference(price1, price2):
return price1 - price2
diff --git a/saleor/product/views.py b/saleor/product/views.py
index 634cfcd889..b9c3c7910e 100644
--- a/saleor/product/views.py
+++ b/saleor/product/views.py
@@ -15,7 +15,7 @@ def get_related_products(product):
if not product.collection:
return []
related_products = Product.objects.filter(
- collection=product.collection)
+ collection=product.collection).exclude(id=product.id)
related_products = related_products.prefetch_related('images')
return related_products
diff --git a/saleor/settings.py b/saleor/settings.py
index f2711e20f4..5dcf8871c0 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -121,8 +121,8 @@ INSTALLED_APPS = [
'saleor.dashboard',
# External apps
+ 'versatileimagefield',
'babeldjango',
- 'django_images',
'django_prices',
'emailit',
'mptt',
diff --git a/saleor/urls.py b/saleor/urls.py
index 86305a80f3..960f4d0f06 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -25,7 +25,6 @@ urlpatterns = patterns(
url(r'^cart/', include(cart_urls, namespace='cart')),
url(r'^checkout/', include(checkout_urls, namespace='checkout')),
url(r'^dashboard/', include(dashboard_urls, namespace='dashboard')),
- url(r'^images/', include('django_images.urls')),
url(r'^order/', include(order_urls, namespace='order')),
url(r'^products/', include(product_urls, namespace='product')),
url(r'^profile/', include(userprofile_urls, namespace='profile')),
diff --git a/setup.py b/setup.py
index 0ae28623da..694832f734 100755
--- a/setup.py
+++ b/setup.py
@@ -20,13 +20,13 @@ setup(
'Django>=1.7',
'dj_database_url>=0.3.0',
'django-emailit>=0.2.2',
- 'django-images>=0.4.2,<0.5a0',
'django-model-utils>=2.0.0,<2.1a0',
'django-mptt>=0.7.1',
'django-offsite-storage>=0.0.5',
'django-payments>=0.6.1,<0.7a0',
'django-prices>=0.3.3,<0.4a0',
'django-selectable==0.8.0',
+ 'django-versatileimagefield>=1.0.1,<1.1a0'
'fake-factory>=0.3.2',
'google-measurement-protocol>=0.1.2,<0.2a0',
'Markdown>=2.4',
diff --git a/utils/create_random_data.py b/utils/create_random_data.py
index 8e5017a685..6bd3c8b51c 100644
--- a/utils/create_random_data.py
+++ b/utils/create_random_data.py
@@ -61,7 +61,6 @@ def create_product(product_type, **kwargs):
def create_variant(product, **kwargs):
defaults = {
'stock': fake.random_int(),
- 'name': fake.word(),
'sku': fake.random_int(1, 100000),
'product': product
}