Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Show only featured products on homepage
Artur Smętbcd0c55aa359
diff --git a/saleor/core/management/commands/populatedb.py b/saleor/core/management/commands/populatedb.pyindex c0ecfdd86e..3db8748a92 100644--- a/saleor/core/management/commands/populatedb.py+++ b/saleor/core/management/commands/populatedb.py@@ -4,7 +4,8 @@ from django.db import connectionfrom ...utils.random_data import (create_orders, create_users, create_shipping_methods,- create_products_by_schema, create_product_sales, create_vouchers)+ create_products_by_schema, create_product_sales, create_vouchers,+ set_featured_products)from ...utils import create_superuser@@ -61,6 +62,8 @@ class Command(BaseCommand):self.stdout.write(msg)for msg in create_orders(20):self.stdout.write(msg)+ for msg in set_featured_products(16):+ self.stdout.write(msg)if options['createsuperuser']:credentials = {'email': '[email protected]', 'password': 'admin'}diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex e6aecf5b5b..994897b8c3 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -503,3 +503,9 @@ def create_vouchers():yield 'Voucher #%d' % voucher.idelse:yield 'Value voucher already exists'+++def set_featured_products(how_many=8):+ pks = Product.objects.order_by('?')[:how_many].values_list('pk', flat=True)+ Product.objects.filter(pk__in=pks).update(is_featured=True)+ yield 'Featured products created'diff --git a/saleor/core/views.py b/saleor/core/views.pyindex 21aca8ec94..7c76618b08 100644--- a/saleor/core/views.py+++ b/saleor/core/views.py@@ -4,7 +4,7 @@ from ..product.utils import products_with_availability, products_with_detailsdef home(request):- products = products_with_details(request.user)[:8]+ products = products_with_details(request.user).filter(is_featured=True)[:8]products = products_with_availability(products, discounts=request.discounts, local_currency=request.currency)return TemplateResponse(diff --git a/saleor/product/migrations/0029_product_is_featured.py b/saleor/product/migrations/0029_product_is_featured.pynew file mode 100644index 0000000000..c32f926e1b--- /dev/null+++ b/saleor/product/migrations/0029_product_is_featured.py@@ -0,0 +1,20 @@+# -*- coding: utf-8 -*-+# Generated by Django 1.10.5 on 2017-01-30 10:12+from __future__ import unicode_literals++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ('product', '0028_merge_20170116_1016'),+ ]++ operations = [+ migrations.AddField(+ model_name='product',+ name='is_featured',+ field=models.BooleanField(default=False, verbose_name='is featured'),+ ),+ ]diff --git a/saleor/product/models/base.py b/saleor/product/models/base.pyindex 3eff9a2281..220deaf915 100644--- a/saleor/product/models/base.py+++ b/saleor/product/models/base.py@@ -137,6 +137,8 @@ class Product(models.Model, ItemRange, index.Indexed):default={})updated_at = models.DateTimeField(pgettext_lazy('Product field', 'updated at'), auto_now=True, null=True)+ is_featured = models.BooleanField(+ pgettext_lazy('Product field', 'is featured'), default=False)objects = ProductManager()diff --git a/templates/dashboard/product/product_form.html b/templates/dashboard/product/product_form.htmlindex cfcac011a0..e10bf369b9 100644--- a/templates/dashboard/product/product_form.html+++ b/templates/dashboard/product/product_form.html@@ -113,6 +113,7 @@{{ product_form.weight|materializecss:"input-field s12" }}{{ product_form.categories|materializecss:"input-field s12" }}{{ product_form.available_on|materializecss:"input-field s12" }}+ {{ product_form.is_featured|materializecss:"input-field s12" }}</div></div>